This is my php code
<?php
$host = "localhost";
$username = "root";
$password = "";
$db_name = "test1";
$tbl_name = "test_mysql";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$name = (isset($_POST['name'])) ? $_POST['name'] : '';
$lastname = (isset($_POST['lastname'])) ? $_POST['lastname'] : '';
$email = (isset($_POST['email'])) ? $_POST['email'] : '';
$sql = "INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')";
$result = mysql_query($sql);
if ($result) {
echo "Successful";
echo "<BR>";
echo "<a href='insert_ac.php'>Back to main page</a>";
} else {
echo "ERROR";
}
mysql_close();`enter code here`
?>
I am able to insert values to db,but after that if i click "back to main page" to insert more, i am getting the errors as shown below
Notice: Undefined variable: name in C:\xampp\htdocs\PhpProject3(Insert)\insert_ac.php on line 25
Notice: Undefined variable: lastname in C:\xampp\htdocs\PhpProject3(Insert)\insert_ac.php on line 25
Notice: Undefined variable: email in C:\xampp\htdocs\PhpProject3(Insert)\insert_ac.php on line 25
Successfully Inserted
To insert more...Back to main page
How can I fix this???