shalli Posted December 30, 2010 Share Posted December 30, 2010 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/223018-problem-with-a-simple-edit-page-functionality/ Share on other sites More sharing options...
.josh Posted December 30, 2010 Share Posted December 30, 2010 you sure it's not updating? The order in which you have your code setup it should make the update when you submit but since there is no $_GET when you submit, your code doesn't turn around and query for it so it looks like it shows up blank or not updated (because your condition only does one or the other, not both). Try refreshing the page after submit to test (or look directly in your db), you should see the updated. You will have to reorder/rewrite your code to do the query to show the data regardless of whether you posted or not. p.s. - use [ code] ...[ /code] tags when posting code. Quote Link to comment https://forums.phpfreaks.com/topic/223018-problem-with-a-simple-edit-page-functionality/#findComment-1153054 Share on other sites More sharing options...
shalli Posted December 30, 2010 Author Share Posted December 30, 2010 thanks for your response Crayon Violent Yes it seems to do nothing I entered the following echo to check that I was passing the correct variables echo "$ProductName <br> $ProductText <br> $ProductImage <br> $ProductPrice"; Basically what the code does is display a form with the data from the database and you edit that data in the form and when you click submit it should update the database I was using this tutorial to help me create this functionality http://www.maaking.com/index.php?loadpage=tutorials hope this help Quote Link to comment https://forums.phpfreaks.com/topic/223018-problem-with-a-simple-edit-page-functionality/#findComment-1153060 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.