In this tutorial we are going to learn how to insert data into mysql table.After Creating Database and table now we can insert data into database.for that copy the code and paste it into your file and modify the connection string acoording to your need nd run the code.if all go well then the below sql statememnt will be executed and data will be shown into your table.
<?php
$servername = "localhost";
$username = "your username";
$password = "your password";
$dbname = "your database name";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO Your_table_name(firstname, lastname, email)
VALUES ('Asdf', 'Qwerty', 'asdf@example.com')";
if ($conn->query($sql) === TRUE)
{
echo "New record created successfully";
}
else
{
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
Happy Coding...
0 Comments