LittleB Posted April 28, 2009 Share Posted April 28, 2009 Hello! I am having a hard time trying to edit records in a table. I have a php page that lists all records in a table: ... echo '<tr class="list"> <td>' . $data['Product_Name'] . '</td> <td>' . $data['Prd_Gender'] . '</td> <td>' . $data['Quantity'] . '</td> <td><a href="edit_product.php?Product_ID='.$data['Product_ID'].'">Edit</a></td> </tr>'; ... clicking the Edit link takes me to another php page (edit_product.php), which fetches values of the selected product_id and inserts them in a form ready for editing: ... if (isset($_POST['p_submitted'])){ // DEFINING MY VARIABLES $Product_ID=$_POST['Product_ID']; $prd_name=$_POST['prd_name']; $prd_gender=$_POST['prd_gender']; $prd_quantity=$_POST['prd_quantity']; //make the query $query = "UPDATE product SET Product_Name = '$prd_name', Prd_Gender = '$prd_gender', Quantity = '$prd_quantity' WHERE Product_ID='$Product_ID'"; $result_edit=@mysql_query($query);// run the query exit; } $Product_ID=$_GET['Product_ID']; $result_view=@mysql_query("SELECT * FROM Product WHERE Product_ID='$Product_ID'"); $data=mysql_fetch_assoc($result_view); // editing records: http://www.phpsimple.net/mysql_update_record.html ?> ... Now everytime i try to update, i get this message: Notice: Undefined index: Product_ID in C:\wamp\www\edit_product.php on line 9 Line 9 being: $Product_ID=$_POST['Product_ID']; I understand why it does that; there is no 'Product_ID' element in my html form but i'm trying to get the Variable Product_ID from the previous page to decide what record to update. Sorry if the code is long. I would appreciate any help Link to comment https://forums.phpfreaks.com/topic/156041-edit-database-table-using-phphtml-form/ Share on other sites More sharing options...
herghost Posted April 29, 2009 Share Posted April 29, 2009 Store it in a session on your previous page and call it on this one using session_start(); Link to comment https://forums.phpfreaks.com/topic/156041-edit-database-table-using-phphtml-form/#findComment-821479 Share on other sites More sharing options...
Helmet Posted April 29, 2009 Share Posted April 29, 2009 You're passing Product_ID in the querystring, so that one is part of the _GET array. The others are _POST (if the form method is set as such). Either make Product_ID a hidden field in your post form or change the code on the second page to look for $_GET['Product_ID'] Link to comment https://forums.phpfreaks.com/topic/156041-edit-database-table-using-phphtml-form/#findComment-821502 Share on other sites More sharing options...
LittleB Posted April 29, 2009 Author Share Posted April 29, 2009 Thank you!!!!!!! Here is what I did, I created a type hidden with value = "<?php echo $data['Product_ID']; ?>" It does update but now I want to solve another problem. The form action currently is "<?php echo $_SERVER['PHP_SELF']; ?>" , when a record is edited it just takes me to a blank page. I need to go back to view_products, hit refresh to be able to see the changes. I tried setting action to product.php page but it inserts the edited record rather than editing an existing one. What can I do to get directed to the refreshed product.php automatically. Thanks again!! Link to comment https://forums.phpfreaks.com/topic/156041-edit-database-table-using-phphtml-form/#findComment-821606 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.