Php 代码不更新

Php 代码不更新,php,sql,sql-update,edit,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 col

我有一个编辑表单,将搜索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!";
}

?>

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

少数可能出现的错误之一

$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的值放在一个隐藏的表单字段中

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

你能去掉多余的代码吗?我愿意帮忙,但不想筛选那么多文本。代码不起作用。你能说得更具体一点吗?根本没有更新。我有一个不同的表相同的代码,但它在那里工作。对于这个特定的表,它不会更新。不再支持mysql_*函数,它们不再被维护,将来也会被维护。您应该使用或更新代码,以确保将来项目的功能。未定义资产\u ID感谢您的帮助。