我正在腳本上更新記錄。該腳本在我看來很好,我也收到了成功消息,但該記錄未在數據庫中更新。請幫我解決這個問題。更新MYSQL記錄錯誤
這是我的表單頁面。
<!-- Inquiry Table Stars here -->
<?php
$id=$_GET['id'];
$sql = "Select * From inquiry WHERE id='$id'";
$result = mysql_query($sql);
?>
<?php
while($row=mysql_fetch_array($result))
{
$name = $row['cname'];;
$email = $row['email'];;
$phone = $row['phone'];;
$sdate = $row['sdate'];;
$edate = $row['edate'];;
$fdate = $row['fdate'];;
?>
<!-- Code Begins -->
<center>
<div class="vpb_main_wrapper">
<br clear="all">
<form method="post" action="edit_ac.php">
<h2 align="left" style="margin-top:0px;">Edit Operator</h2><br />
<div align="left" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; margin-bottom:10px;">Edit operator Details.</div><br />
<div style="width:115px; padding-top:10px;float:left;" align="left"> Full Name:</div>
<div style="width:300px;float:left;" align="left"><input type="text" name="cname" id="cname" value="<?php echo $name; ?>" class="vpb_textAreaBoxInputs" required>
</div><br clear="all"><br clear="all">
<div style="width:115px; padding-top:10px;float:left;" align="left"> Email:</div>
<div style="width:300px;float:left;" align="left"><input type="text" name="email" id="email" value="<?php echo $email; ?>" class="vpb_textAreaBoxInputs" required>
</div><br clear="all"><br clear="all">
<div style="width:115px; padding-top:10px;float:left;" align="left">Mobile:</div>
<div style="width:300px;float:left;" align="left"><input type="text" name="phone" id="phone" value="<?php echo $phone; ?>" required class="vpb_textAreaBoxInputs">
</div><br clear="all"><br clear="all">
<div style="width:115px; padding-top:10px;float:left;" align="left">Start Date:</div>
<div style="width:300px;float:left;" align="left"><input type="text" name="sdate" id="sdate" value="<?php echo $sdate; ?>" required class="vpb_textAreaBoxInputs">
</div><br clear="all"><br clear="all">
<div style="width:115px; padding-top:10px;float:left;" align="left">End Date:</div>
<div style="width:300px;float:left;" align="left"><input type="text" name="edate" id="edate" value="<?php echo $edate; ?>" required class="vpb_textAreaBoxInputs">
</div><br clear="all"><br clear="all">
<div style="width:115px; padding-top:10px;float:left;" align="left">Date of Journey:</div>
<div style="width:300px;float:left;" align="left"><input type="text" name="fdate" id="fdate" value="<?php echo $fdate; ?>" class="vpb_textAreaBoxInputs" required>
</div><br clear="all"><br clear="all">
<input name="id" type="hidden" id="id" value="<?php echo $row['id']; ?>">
<div style="width:115px; padding-top:10px;float:left;" align="left"> </div>
<div style="width:300px;float:left;" align="left">
<input type="submit" name="submit" id="submit" value="Submit" style="margin-left: 100px" class="vpb_general_button">
</div>
</form>
<br clear="all"><br clear="all">
</div><?php } ?>
</center>
<!-- Code Ends -->
<!-- Inquiry Table Ends here -->
,這裏是我的edit_ac.php
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="pro1"; // Database 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");
$name = $_POST['cname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$sdate = $_POST['sdate'];
$edate = $_POST['edate'];
$fdate = $_POST['fdate'];
// update data in mysql database
$sql="UPDATE inquiry SET
cname = '$name',
email = '$email',
phone = '$phone',
sdate = '$sdate',
edate = '$edate',
fdate = '$fdate'
WHERE id='$id'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successfull";
}
else {
echo "Error";
}
?>
它顯示 「0記錄更新成功」。所以它沒有在數據庫中更新。什麼問題請幫助。
在後面的腳本中沒有設置像'$ id'這樣的值。你只是假設它已經設置好了,但它們並不是。 – davidkonrad 2015-02-10 10:18:12
我也做了$ _POST也沒有工作 – 2015-02-10 10:19:31
再次看到帖子我編輯了edit_ac.php頁面...仍然沒有工作.. – 2015-02-10 10:20:58