davids_media Posted May 7, 2012 Share Posted May 7, 2012 I have three pages; edit_records.php (list of records, user picks one ready to edit, works fine) update.php (by in large works fine, heres the code for it anyway) <?php require_once ('./includes/config.inc.php'); require_once (MYSQL); if($id = isset($_GET['prodID'])) { $query = "SELECT * FROM product WHERE prodID='{$_GET['prodID']}'"; $r = mysqli_query($dbc, $query); while ($row = mysqli_fetch_array($r)) { $id = $row['prodID']; $product = $row ['product']; ?> <form action="update_save.php" method="post"> ID: <input type="text" value="<?php echo $id;?>" name="id" disabled="disabled" /> Product: <input type="text" value="<?php echo $product;?>" name="product" /> <br /> <input type="submit" value="submit changes" /> </form> <?php } } and finally update_save.php (this is where the actual updating takes place) <?php require_once ('./includes/config.inc.php'); require_once (MYSQL); $product = $_POST['product']; $query = "UPDATE product SET product = $product WHERE prodID = '$id'"; $r = mysqli_query($dbc, $query); echo 'Database Updated!!'; ?> however, on line 19 of update save, i get this error; An error occurred in script 'C:\Users\David Morgan\Desktop\WEBSITES\hairz_&_graces\site\admin\update_save.php' on line 9: Undefined variable: id now I am aware i should really create a variable but since i already stored it in update.php, i had hoped it would work but it hasnt. what should i do? help would be much appreciated please Quote Link to comment https://forums.phpfreaks.com/topic/262205-problem-updating-record/ Share on other sites More sharing options...
Colton.Wagner Posted May 7, 2012 Share Posted May 7, 2012 You forgot to set your variable id if you notice you set the variable product but did not set the id. This should resolve the issue. <?php require_once ('./includes/config.inc.php'); require_once (MYSQL); $id = $_POST['id']; $product = $_POST['product']; $query = "UPDATE product SET product = $product WHERE prodID = '$id'"; $r = mysqli_query($dbc, $query); echo 'Database Updated!!'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/262205-problem-updating-record/#findComment-1343709 Share on other sites More sharing options...
davids_media Posted May 7, 2012 Author Share Posted May 7, 2012 i now get an error message: undefined index id i have tried using $id = ['prodID'] (prodID being the unique ID of the table) and $id = ['id'] but to no avail Quote Link to comment https://forums.phpfreaks.com/topic/262205-problem-updating-record/#findComment-1343711 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.