I have a database with content.
I have a page that displays a table of all records. You can click edit for any record you wish, when you click edit it redirects you to a new form and populates all the information into some form feilds.
When you edit the form values and click submit it is supposed to update the record in the database.
I get a success message when I update,but the record doesnt actually update.
form.php:
<?php
$emp_id= ($_GET["id"]);
$sql = "SELECT * FROM people
WHERE id='$emp_id' LIMIT 1";
$result = mysql_query($sql);
$row_people = mysql_fetch_array($result);
?>
<form method="post" action="update.php?id=<?php echo "$emp_id" ?>">
<input type="hidden" name="id" value="<?php echo "$row_people[id]"; ?>">
<fieldset>
<legend><b>Name</b></legend>
First Name:<input type="text" name="first_name" size="20" value="<?php echo "$row_people[first_name]"; ?>">
Last Name:<input type="text" name="last_name" size="40" value="<?php echo "$row_people[last_name]"; ?>">
</fieldset>
update.php
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="ogs"; // Database name
$tbl_name="people"; // 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");
$emp_id= ($_GET["id"]);
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
// update data in mysql database
$sql="UPDATE $tbl_name SET first_name='$first_name', last_name='$last_name' WHERE id='$emp_id' LIMIT 1";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
}
else {
echo "ERROR";
}
?>
Not sure what I am missing.
If i change the $first_name in my query to actual text, it updates fine.
So I'm assuming something is wrong with my form.php or the $_POST?