This is because there was an error in your query, in which case $result is set to false. You should check for errors arter each mysql_query like you do with mysql_connect and mysql_select_db.
I have solved my first problem. Now I am facing problem to update my tabel with below script.
"
Mysql error, data not saved, try again -You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE id=’‘’ at line 5
"
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="merchandising"; // Database name
//$tbl_name="test_mysql"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// update data in mysql database
//$sql="UPDATE test_mysql SET name='$name', lastname='$lastname',
//$result=mysql_query($sql);
$sql = mysql_query("UPDATE test_mysql
SET name='$name',
lastname='$lastname',
email='$email',
WHERE id='$id'");
if (!$sql) {
echo 'Mysql error, data not saved, try again -' . mysql_error();
}else{
// echo 'Your data was inserted';
echo "<a href='list_records.php'>View result</a>";
}
?>
//Your code;
$sql = mysql_query("UPDATE test_mysql
SET name='$name',
lastname='$lastname',
email='$email',
WHERE id='$id'");
//After modifications;
//(means after last column no ',' required and $id is not defined above the code;
$id=$_GET['id'];
$sql = mysql_query("UPDATE test_mysql
SET name='$name',
lastname='$lastname',
email='$email'
WHERE id='$id'");