I'm relatively new to php and mysql. What I'm trying to do in this section of code is update 2 columns of information in a database based on the inputs of 2 text boxes. Whenever I try and update the values in the database they update to 0. I placed echo statements after I declared the $ variables and the values of both variables was the same as what I had typed into the boxes. But when I run the sql_query the new values in the database are 0 rather than the values of the 2 $ variables. Any help would be much appreciated! Thanks in advance!
<?php
$result = mysql_query("SELECT * from place_order ORDER BY item_name;");
echo "<form action='' method='POST'>Select an item:<select name='selection'><option>Select...</option>";
while ($row = mysql_fetch_assoc($result))
{
$item_name = $row["item_name"];
echo "<option>$item_name</option>";
}
echo "</select>
<input type='submit' value='Select Item' style='float:right;'/>";
$selection = $_POST['selection'];
echo "<br><br>Type the updated information into the text fields<br><br>";
echo "
<table width='300'>
<tr>
<td align='left'>Item Cost(€): </td>
<td align='left'><input type='text' name='cost'></td>
</tr>
<tr>
<td align='left'>Item Quantity: </td>
<td align='left'><input type='text' name='quantity'></td>
</tr>
<tr>
<td align='left'></td>
<td align='left'><input type='submit' name='button' value='Submit'></td>
</tr>
</table>
";
$cost = $_POST['cost'];
$quantity = $_POST['quantity'];
$selection = $_POST['selection'];
$sql = "UPDATE place_order SET item_cost='$cost', quantity='$quantity' WHERE item_name='$selection' ORDER BY item_name;;";
$query_update = mysql_query($sql);
if($query_update)
{
echo "Table updated! Click View Stock in the menu to view the updated table";
}
echo"</form>";
?>