douxun4860 2012-04-10 11:46
浏览 55

使用带有下拉选项的php更新mysql数据

I am trying to update my products table using a product form but it is throwing an error for an undefined variable here is my code for the 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"/>

Undefined variable all lines, do i have to do anything differently if using drop down areas*

*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");    
      }    
 ?>
  • 写回答

2条回答 默认 最新

  • dpdhnd3577 2012-04-10 11:59
    关注

    i think $row vairable is used to get values from database which you have missed

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

    then your code will work

    $supplId= $row['supplId'];
    ...
    
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序