Hi There
I am trying to create a page that edit mysql database from a php page. I can get the edit page to show the orginal information but it wont update the data in the mysql database.
I am sure I have entered everything right. If anyone could help with this I would greatly appreciated
<?php
include("dbconnect.php");
if(isset($_POST['submit']))
{
// Set global variables to easier names
// and prevent sql injection and apostrophe to break the db.
$ProductName = mysql_escape_string($_POST['ProductName']);
$ProductText = mysql_escape_string($_POST['ProductText']);
$ProductImage = mysql_escape_string($_POST['ProductImage']);
$ProductPrice = mysql_escape_string($_POST['ProductPrice']);
$result = mysql_query("UPDATE Product SET ProductName='$ProductName', ProductText='$ProductText', ProductImage='$ProductImage', ProductPrice='$ProductPrice' WHERE ID='$ID' ",$dbconnect);
echo "<b>Thank you! Product UPDATED Successfully!<br>You'll be redirected to View Page after (2) Seconds";
echo "<meta http-equiv=Refresh content=2;url=view.php>";
echo "$ProductName <br> $ProductText <br> $ProductImage <br> $ProductPrice";
}
elseif(isset($_GET['ID']))
{
$result = mysql_query("SELECT * FROM Product WHERE ID='$_GET[iD]' ",$dbconnect);
while($myrow = mysql_fetch_assoc($result))
{
$ProductName = $myrow["ProductName"];
$ProductText= $myrow["ProductText"];
$ProductImage = $myrow["ProductImage"];
$ProductPrice = $myrow["ProductPrice"];
?>
<br>
<h3>::Edit Product</h3>
<form method="post" action="<?php echo $PHP_SELF ?>">
<input type="hidden" name="ID" value="<? echo $myrow['ID']?>">
Product Name: <input name="ProductName" size="40" maxlength="255" value="<? echo $ProductName; ?>"><br>
Product Text: <textarea name="ProductText" rows="7" cols="30"><? echo $ProductText; ?></textarea><br>
Product Image: <textarea name="ProductImage" rows="7" cols="30"><? echo $ProductImage; ?></textarea><br>
Product Price: <textarea name="ProductPrice" rows="7" cols="30"><? echo $ProductPrice; ?></textarea><br>
<input type="submit" name="submit" value="Update Product">
</form>
<?
}//end of while loop
}//end else
?>