谁能帮我?
看来我无法使用我制作的这段代码更新我的数据库。
我不知道错了。
我想在表单中显示旧数据的同时更新指定 ID 的整行。
我该如何纠正?
<?php //upd_emp.php
mysql_connect ("localhost", "root","") or die (mysql_error());
mysql_select_db ("emp_db0");
$id =$_POST['emp_idn'];
$result = mysql_query("SELECT * FROM emp_tbl WHERE emp_id = '$id'");
$test = mysql_fetch_array($result);
if (!$result)
{
die("Error: Data not found..");
}
$fname=$test['fname'] ;
$mname= $test['mname'] ;
$lname=$test['lname'] ;
$email=$test['email'] ;
if(isset($_POST['SAVE']))
{
$f_save = $_POST['f_name'];
$m_save = $_POST['m_name'];
$l_save = $_POST['l_name'];
$e_save = $_POST['e_mail'];
mysql_query("UPDATE emp_tbl SET fname ='$f_save', mname ='$m_save',
lname ='$l_save',email ='$e_save' WHERE emp_id = '$id'")
or die(mysql_error());
echo "Saved!";
}
?>
<form action = "upd_emp.php" method="post">
First Name:<input type="text" name="f_name" value="<?php echo $fname ?>"/>
Middle Initial:<input type="text" name="m_name" value="<?php echo $mname ?>"/>
Last Name:<td><input type="text" name="l_name" value="<?php echo $lname ?>"/>
Email Add:<input type="text" name="e_mail" value="<?php echo $email ?>"/>
<input type="submit" name="save" value="SAVE" />
</form>
This code here at top came from a form page after clicking the submit button "view.php"
<?php $id =$_POST['emp_idn']; ?>