captchadreams
Power Member
- Sep 19, 2008
- 509
- 133
I found a tutorial that I was messing around with while trying to learn php and mysql and I've received an error on the last part of the script where it's suppose to update some table data. The error said that the variable wasn't defined.. when looking at the last script file.. it looks like he really didn't define the variable in his tutorial.. but I'm also new and could be wrong.
here it is:
this is the part where I get the error from: $sql="UPDATE $tbl_name SET name='$name', lastname='$lastname', email='$email' WHERE id='$id'";
I'm wondering if someone can take a look at this tutorial and see if he actually didn't define the variable himself.
http://www.phpeasystep.com/mysql/9.html
if so.. if anyone would be willing to rewrite the end of that code for me, it would be much appreciated.
here it is:
Code:
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // 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 $tbl_name SET name='$name', lastname='$lastname', email='$email' WHERE id='$id'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='list_records.php'>View result</a>";
}
else {
echo "ERROR";
}
?>
this is the part where I get the error from: $sql="UPDATE $tbl_name SET name='$name', lastname='$lastname', email='$email' WHERE id='$id'";
I'm wondering if someone can take a look at this tutorial and see if he actually didn't define the variable himself.
http://www.phpeasystep.com/mysql/9.html
if so.. if anyone would be willing to rewrite the end of that code for me, it would be much appreciated.