代码没有更新

时间:2014-07-07 00:53:35

标签: php sql sql-update edit

我有一个编辑表单,它将搜索ID并在同一页面中编辑它。然后把它扔到另一个页面,它会显示它是成功的。

<body bgcolor = "#FFFFFF" text = "#000000">
<form name = "ReadID" method="post">
<table width = "350" border = "0" align="center" cellpadding = "3" >
    <tr>
        <td colspan = "2" bgcolor = "#EF8D25" height = "23">
            <center><b>Search</b></center>
        </td>
    </tr>
    <tr bgcolor = "#eeeeee">
        <td width = "40%" bgcolor = "#eeeeee">
        <center>Asset ID</center>
        </td>
    <td width = "60%">
        <input id="text" type = "text" name = "ASSET_ID">
        </td>
    </tr>
        <td colspan   = "2" bgcolor = "#EF8D25">
            <center>
                <input type = "submit" name = "Submit" value = "Search" onclick="showElem()">
            </center>
        </td>
    </tr>
</table>
</form>

<form name="displayform" method="post" action="edititem.php">
<table width="350" border="0" align="center" cellpadding="3" id="111">
<tr>
<td colspan="2" bgcolor="#EF8D25">
<div align="center"><b>Edit Form</b></div>
</td>
</tr>
<?php
$host = "localhost";
$uname = "root";
$pass = "";
$tablename = "tb_asset";
$con = mysql_connect($host, $uname, $pass)
  or die ("Database connection failed!<br>");
 mysql_select_db("db_itinventory",$con);
$ASSET_ID = $_POST['ASSET_ID'];
$sql="select * from tb_asset where ASSET_ID='$ASSET_ID'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
?>
 <tr bgcolor="#eeeeee">
  </tr>
  <tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align="right" >Barcode</div>
</td>
<td width = "150">
<input id="text" type="text" name = "Barcode" value ="<?php echo $row['Barcode']; ?>"/>
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Item Name</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Item_Name" value="<?php echo $row['Item_Name']; ?>" />
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Serial</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Serial" value="<?php echo $row['Serial']; ?>" />
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Brand</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Brand" value="<?php echo $row['Brand']; ?>" />
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Model</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Model" value="<?php echo $row['Model']; ?>" />
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Status</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Status" value="<?php echo $row['Status']; ?>" />
</td>
</tr>
<td colspan="2" bgcolor="#EF8D25" >
<div align="center"> 
<input  type="submit" name="Submit" value="Update" />
</div>
</td>
</tr>
</table>
</form>
</body>
</html>

这是第二页。

<?php
$user_name = "root";
$password = "";
$database = "db_itinventory";
$server = "localhost";

mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database);

$ASSET_ID = trim(mysql_real_escape_string($_POST["ASSET_ID"]));
$Barcode = trim(mysql_real_escape_string($_POST["Barcode"]));
$Item_Name = trim(mysql_real_escape_string($_POST["Item_Name"]));
$Serial = trim(mysql_real_escape_string($_POST["Serial"]));
$Brand = trim(mysql_real_escape_string($_POST["Brand"]));
$Model = trim(mysql_real_escape_string($_POST["Model"]));
$Status = trim(mysql_real_escape_string($_POST["Status"]));

$sql = ("Update tb_asset set  Barcode = '".$Barcode."' , Item_Name = '".$Item_Name."' , Serial = '".$Serial."' , Brand = '".$Brand."' , Model = '".$Model."' , Status = '".$Status."' where ASSET_ID = '".$ASSET_ID."'");

$result=mysql_query($sql);

if ($result){
echo "<center><table border = \"0\" align = \*center\* cellspacing = \"1\" cellpadding = \"5\" width = \"350\">";
echo "<tr>";
echo "<td colspan = \"2\" bgcolor = \"#EF8D25\">";
echo "<center><b>Record successfully edited!</b></center>";
echo "</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"20\">";
echo "<div align = \"right\">Barcode</div>";
echo "</td>";
echo "<td width = \"550\">".$Barcode."</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Item_Name</div>";
echo "</td>";
echo "<td width = \"200\">".$Item_Name."</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Serial</div>";
echo "</td>";
echo "<td width = \"200\">".$Serial."</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Brand</div>";
echo "</td>";
echo "<td width = \"200\">".$Brand."</td>";
echo "</tr>";
//echo "<tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Model</div>";
echo "</td>";
echo "<td width = \"200\">".$Model."</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Status</div>";
echo "</td>";
echo "<td width = \"200\">".$Status."</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan = \"2\" bgcolor = \"#EF8D25\">&nbsp;</td>";
echo "</tr>";
echo "</table>";
}
else {
echo "ERROR!";
}

?>

没有错误显示。但是代码不起作用。帮助

1 个答案:

答案 0 :(得分:0)

少数可能的错误之一..

$sql = ("Update tb_asset set  Barcode = '".$Barcode."' , Item_Name = '".$Item_Name."' , Serial = '".$Serial."' , Brand = '".$Brand."' , Model = '".$Model."' , Status = '".$Status."' where ASSET_ID = '".$ASSET_ID."'");

*不应该有任何括号。

关于未定义的ASSET_ID:

您可能希望将ASSET_ID的值放在隐藏的表单字段

<input type="hidden" name = "ASSET_ID" value ="<?php echo $row['ASSET_ID']; ?>"/>