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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.