Note that there are some explanatory texts on larger screens.

plurals
  1. POupdating mysql data using php with a drop down option
    primarykey
    data
    text
    <p><em><strong>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</em></strong></p> <pre><code>&lt;?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']; } ?&gt; //form &lt;form action="Edit_Prod.php" method="post"&gt; &lt;input type="hidden" name="ProductID" value="&lt;?php echo $ProductID; ?&gt;"/&gt; &lt;label&gt;Product Description: &lt;span class="small"&gt;Please enter a description for the product &lt;/span&gt; &lt;/label&gt; &lt;input type="text" name="ProdDesc" value="&lt;?php echo $ProdDesc ;?&gt;" /&gt; &lt;label&gt;Supplier ID &lt;span class="small"&gt;Please enter the Supplier ID&lt;/span&gt; &lt;/label&gt; &lt;input type="text" name="SupplierID" value="&lt;?php echo $SupplierID ;?&gt;" /&gt; &lt;label&gt;Bay Location: &lt;span class="small"&gt;Please select the bay location for this product &lt;/span&gt; &lt;/label&gt; &lt;select name="Location" value="&lt;?php echo $Location ;?&gt;" /&gt; &lt;option&gt;A1&lt;/option&gt; &lt;option&gt;A2&lt;/option&gt; &lt;option&gt;A3&lt;/option&gt; &lt;option&gt;A4&lt;/option&gt; &lt;option&gt;A5&lt;/option&gt; &lt;option&gt;B1&lt;/option&gt; &lt;option&gt;B2&lt;/option&gt; &lt;option&gt;B3&lt;/option&gt; &lt;option&gt;B4&lt;/option&gt; &lt;option&gt;B5&lt;/option&gt; &lt;option&gt;C1&lt;/option&gt; &lt;option&gt;C2&lt;/option&gt; &lt;option&gt;C3&lt;/option&gt; &lt;option&gt;C4&lt;/option&gt; &lt;option&gt;C5&lt;/option&gt; &lt;option&gt;D1&lt;/option&gt; &lt;option&gt;D2&lt;/option&gt; &lt;option&gt;D3&lt;/option&gt; &lt;option&gt;D4&lt;/option&gt; &lt;option&gt;D5&lt;/option&gt; &lt;option&gt;E1&lt;/option&gt; &lt;option&gt;E2&lt;/option&gt; &lt;option&gt;E3&lt;/option&gt; &lt;option&gt;E4&lt;/option&gt; &lt;option&gt;E5&lt;/option&gt; &lt;/select&gt; &lt;label&gt;Product Cost: &lt;span class="small"&gt;Please enter a new cost for the product (per roll) &lt;/span&gt; &lt;/label&gt; &lt;input type="text" name="Cost" value="&lt;?php echo $Cost ;?&gt;" /&gt; &lt;label&gt;Status: &lt;span class="small"&gt;Please select a status for the product &lt;/span&gt; &lt;/label&gt; &lt;select name="Status" value="&lt;?php echo $Status ;?&gt;" /&gt; &lt;option&gt;Live&lt;/option&gt; &lt;option&gt;Mature&lt;/option&gt; &lt;option&gt;Obsolete&lt;/option&gt; &lt;/select&gt; &lt;label&gt;MRL &lt;span class="small"&gt;Please enter a minimum re-order level for this product &lt;/span&gt; &lt;/label&gt; &lt;input type="text" name="MRL" value="&lt;?php echo $MRL ;?&gt;" /&gt; &lt;input type="submit" value= "Edit Product Details"/&gt; </code></pre> <p><strong>Undefined variable all lines, do i have to do anything differently if using drop down areas*</strong></p> <p>*<strong>Edit_Prod.php*</strong></p> <pre><code>&lt;?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"); } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload