php不会更新UPDATE QUERY

时间:2012-04-20 10:37:15

标签: php mysql arrays variables

说明错误

注意:未定义的变量:第9行的E:\ xampp \ htdocs \ Edit_Supp.php中的行

注意:未定义的索引:第12行的E:\ xampp \ htdocs \ Edit_Supp.php中的id 供应商已更新

代码:Edit_Supp_Form.php

<?php   
$SupplierID = $_GET['id'];
//Connect and select a database
mysql_connect ("localhost", "root", "");
mysql_select_db("supplierdetails");
//Run query
$result1 = mysql_query("SELECT * FROM suppliers WHERE SupplierID=$SupplierID"); 
while($row = mysql_fetch_array($result1)){
$SupplierID = $_GET['id'] = $row['SupplierID']; 
$SupplierID = $row['SupplierID']; 
$SupplierName = $row['SupplierName'];
$Currency = $row['Currency'];
$Location = $row['Location'];
$ContactNumber = $row['ContactNumber'];
$Email = $row['Email'];
  }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-    strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="" />
  <link rel="stylesheet" type="text/css" href="style.css" media="screen" />
 <form action="Edit_Supp.php" method="post">
 <br>
 </br>
 <input type="hidden" name="SupplierID" value="<?php echo $SupplierID;?>"/> 

Supplier Name: <input type="text" name="SupplierName" value="<?php echo $SupplierName ;?>" />
<br>
</br>
 Currency: <input type="text" name="Currency" value="<?php echo $Currency ;?>" />
 <br>
 </br>
 Location: <input type="text" name="Location" value="<?php echo $Location ;?>" />
 <br>
</br>
 Contact Number:<input type="text" name="ContactNumber" value="<?php echo $ContactNumber ;?>" /> 
<br>
</br>
Email:<input type="text" name="Email" value="<?php echo $Email ;?>" />
<br>
</br>
<input type="submit" value= "Edit Supplier Information"/>

 </form>
 </div>
 </body>
 </html> 

// Edit_Sup的代码,这是此页面背后的代码:

<?php
 $con = mysql_connect("localhost", "root", "");  
    mysql_select_db("supplierdetails");   
      if (!$con)     
          {       
        die('Could not connect: ' . mysql_error());        
         }    
 //Run a query        
$SupplierID= $_POST['id'] = $row ["SupplierID"];
 $result1 = mysql_query ("SELECT * FROM suppliers WHERE SupplierID= '".$SupplierID."'") or die    (mysql_error());     
$row = mysql_fetch_array($result1); 
$SupplierID = $_GET['id'];
$SupplierID = $_POST['id'];
$SupplierName = $_POST['SupplierName'];
$Currency = $_POST['Currency'];
$Location = $_POST['Location'];
$ContactNumber = $_POST['ContactNumber'];
$Email = $_POST['Email'];  
$SupplierID = $row['SupplierID'];         
$query = "UPDATE suppliers SET SupplierName = '".$SupplierName."', Currency     = '".$Currency."', Location = '".$Location."', ContactNumber = '".$ContactNumber."', Email = '".$Email."' WHERE SupplierID = '".$SupplierID."'";     
$result1 = mysql_query($query);           
 //Check whether the query was successful or not    
 if($result1) 
{          
 echo "Supplier Updated"; 

 }
else 
{        
 die ("Query failed");    
  }    
 ?>

2 个答案:

答案 0 :(得分:2)

您在$_POST['id']中引用了Edit_sup.php,但我没有看到任何名为id的输入字段。 和Edit_sup.php的第9行读取 -

$SupplierID= $_POST['id'] = $row ["SupplierID"];

我看不到你从{。}}变量那里得到了什么。

答案 1 :(得分:0)

您正试图获得$row['id'],我认为您想要的是$_POST['SupplierID']