But i keep getting the same error: Notice: Undefined index: id in C:\wamp\www\musicwebsite\update.php on line 63
Here is my code for the form which displays all the product information:
Code: Select all
<?php
$id = $_GET['propID'];
@$db = new mysqli( 'localhost', 'root', "", 'k00127082');
if (mysqli_connect_errno())
{
echo 'error connecting to db';
exit;
}
$query = "SELECT * from products where id = '" . $id . "'" ;
$result = $db->query($query);
$row = $result->fetch_object();
//get details from products table
$product_name= $row->product_name;
$product_description = $row->product_description;
$quantity_on_hand = $row->quantity_on_hand;
$price = $row->price;
$image = $row->image;
$image_big = $row->image_big;
$formattedPrice = number_format($price, 2, '.', ',');
$result->free();
$db->close();
?>
</p>
<p>
</p>
<form id ="form1" method="post" name="form1" action="update.php" >
<table width="650" border="1">
<tr>
<td width="150"><label class="contact_form">Product Name </label></td>
<td colspan="2"><input type="text" name="product_name" id="product_name" class="contact_input" value="<?php echo $product_name ?>" /></td>
</tr>
<tr>
<td width="150"><label class="contact_form">Product Description </label></td>
<td colspan="2"><input type="text" name="product_description" id="product_description" class="contact_input" value="<?php echo $product_description ?>" /></td>
</tr>
<tr>
<td width="150"><label class="contact_form">Quantity on Hand </label></td>
<td colspan="2"><input type="text" name="quantity_on_hand" id="quantity_on_hand" class="contact_input" value="<?php echo $quantity_on_hand ?>" /> </td>
</tr>
<tr>
<td width="150"><label class="contact_form">Price</label></td>
<td colspan="2"><input type="text" name="price" id="price" class="contact_input" value="<?php echo $price ?>" /></td>
</tr>
<tr>
<td width="150"><label class="contact_form">Image</label></td>
<td colspan="2"><input type="text" name="image" id="image" class="contact_input" value="<?php echo $image ?>" /></td>
</tr>
<tr>
<td width="150"><label class="contact_form">Big Image</label></td>
<td colspan="2"><input type="text" name="image_big" id="image_big" class="contact_input" value="<?php echo $image_big ?>" /></td>
</tr>
</table>
</br>
<input type="submit" name="submit" id="submit" value="Update Product" />
<INPUT TYPE="BUTTON" VALUE="Go Back" ONCLICK="history.go(-1)">
</form>
Code: Select all
<?php
@$db = new mysqli( 'localhost', 'root', "", 'k00127082');
if (mysqli_connect_errno()) {
echo 'error connecting to db';
exit;
}
$product_name=$_POST["product_name"];
$id = $_POST['id']; //this is line that gets the error
$product_description=$_POST["product_description"];
$quantity_on_hand=$_POST["quantity_on_hand"];
$price=$_POST["price"];
$image=$_POST["image"];
$image_big=$_POST["image_big"];
$query = "UPDATE products SET product_name='$product_name', product_description='$product_description', quantity_on_hand=$quantity_on_hand', price='$price', image='$image', image_big='$image_big' where id = '" . $id . "'" or die(mysql_error());
$result = $db->query($query);
if($result)
echo $db->affected_rows . ' products updated in the database';
else
echo 'There was a problem updating the information in the database';
$db->close();
?>