1

我正在尝试使用产品表单更新我的产品表,但它为未定义的变量抛出错误这是我的 productform.php 代码

<?php
$ProductID= $_GET['ProductID'];
//Connect and select a database
mysql_connect ("localhost", "root", "");
mysql_select_db("supplierdetails");
{
$result = mysql_query("SELECT * FROM products WHERE ProductID=$ProductID");
while($row = mysql_fetch_array($result))
  {
 $ProductID= $_GET['ProductID'];
 $ProdDesc = $row['ProdDesc'];       
 $SupplierID = $row['SupplierID'];   
 $Location = $row['Location'];
 $Cost = $row['Cost'];
 $Status = $row['Status'];
 $MRL = $row['MRL'];        
 $ProductID = $row['ProductID'];   
}     
?>     
//form 
<form action="Edit_Prod.php" method="post">

<input type="hidden" name="ProductID" value="<?php echo $ProductID; ?>"/> 

<label>Product Description:
 <span class="small">Please enter a description for the product </span>
 </label>
 <input type="text" name="ProdDesc" value="<?php echo $ProdDesc ;?>" />
<label>Supplier ID
 <span class="small">Please enter the Supplier ID</span>
 </label>
  <input type="text" name="SupplierID" value="<?php echo $SupplierID ;?>" />
   <label>Bay Location:
 <span class="small">Please select the bay location for this product </span>
 </label>
  <select name="Location" value="<?php echo $Location ;?>" />
 <option>A1</option>
 <option>A2</option>
 <option>A3</option>
 <option>A4</option>
 <option>A5</option>
 <option>B1</option>
 <option>B2</option>
 <option>B3</option>
 <option>B4</option>
 <option>B5</option>
 <option>C1</option>
 <option>C2</option>
 <option>C3</option>
 <option>C4</option>
 <option>C5</option>
 <option>D1</option>
 <option>D2</option>
 <option>D3</option>
 <option>D4</option>
 <option>D5</option>
 <option>E1</option>
 <option>E2</option>
 <option>E3</option>
 <option>E4</option>
 <option>E5</option>
</select>

<label>Product Cost:
 <span class="small">Please enter a  new cost for the product (per roll) </span>
 </label>
  <input type="text" name="Cost" value="<?php echo $Cost ;?>" />

<label>Status:
 <span class="small">Please select a status for the product </span>
 </label>
  <select name="Status" value="<?php echo $Status ;?>" />
 <option>Live</option>
 <option>Mature</option>
 <option>Obsolete</option>
 </select>
 <label>MRL
 <span class="small">Please enter a minimum re-order level for this product </span>
 </label>
 <input type="text" name="MRL" value="<?php echo $MRL ;?>" />
 <input type="submit" value= "Edit Product Details"/>

未定义变量所有行,如果使用下拉区域,我是否必须做任何不同的事情*

* Edit_Prod.php*

<?php
     $con = mysql_connect("localhost", "root", "");  
        mysql_select_db("supplierdetails");   
          if (!$con)     
             {       
        die('Could not connect: ' . mysql_error());        
         }    
      //Run a query        
          $ProductID = $_POST['ProductID'];
      $result = mysql_query ("SELECT * FROM products WHERE Productid= '".$Productid."'") or die(mysql_error());     
      $row = mysql_fetch_array($result); 
      $ProdDesc = $_POST['ProdDesc'];       
      $SupplierID = $_POST['SupplierID'];   
      $Location = $_POST['Location'];
      $Cost = $_POST['Cost'];
      $Status = $_POST['Status'];
      $MRL = $_POST['MRL'];        
      $Productid=$row['Productid'];   
      $query="UPDATE products SET ProdDesc='".$ProdDesc."', SupplierID='".$SupplierID."', Location='".$Location."', Cost='".$Cost."', Status='".$Status."', MRL='".$MRL."' WHERE   ProductID='".$ProductID."'";
      $result = mysql_query($query);  
//Check whether the query was successful or not    
 if($result) 
{          
     echo "Products Updated";
     header ("Location: Products.php");    
 }
else 
{        
     die ("Query failed");    
      }    
 ?>
4

2 回答 2

0

回答您的问题“如果使用下拉区域,我是否必须做任何不同的事情”,当然您必须更改它。改变:

<select name="Location" value="<?php echo $Location ;?>" />
 <option>A1</option>
 <option>A2</option>
 <option>A3</option>
 <option>A4</option>
 <option>A5</option>
.
.

. . ... 至:

<select name="Location"  />
 <option value="<?=$Location;?>" selected="selected" ></option>
 <option>A1</option>
 <option>A2</option>
 <option>A3</option>
 <option>A4</option>
 <option>A5</option>

像那样。我想你明白了。您必须将价值作为选择下的一个选项。试试看。祝你好运。

于 2012-04-17T17:59:13.423 回答
0

我认为 $row vairable 用于从数据库中获取您错过的值

$productID= $_GET['productid'];
$records =mysql_query(" select * from tableName where productid=$productID");

$row=mysql_fetch_array($records);

那么您的代码将起作用

$supplId= $row['supplId'];
...
于 2012-04-10T11:59:07.207 回答