Jump to content

problem updating record


davids_media

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/262205-problem-updating-record/
Share on other sites

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!!';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.