Forum Moderators: coopster
I'm working on a little practice project (in anticipation of a larger one) to try to get the basics down on interacting with a database. The scenario is that someone can enter a user id and retrieve their previously entered data from a database to update it. It works as it should up to the update part now. I'm basing the code on what I've found in "Making Use of PHP."
Here is the code that's used to submit to the database to display the info to be changed:
<form name="form1" method="post" action="tribute_update.php">
<table width="600" border="0" cellspacing="0" cellpadding="6">
<tr align="left">
<td colspan="2">Update Memorial</td>
</tr>
<?php
// Connect to the database
require_once ('../../Connections/mysql_connect.php');
// Get data
// $query = "SELECT * FROM users WHERE memID='" .$memID . "'";
$query = "SELECT * FROM users WHERE memID='" .$memID . "'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
// while (mysql_fetch_array($result))
?>
Date Submitted:
<input name="dateSubmitted" type="text" value="<?php echo $row['dateSubmitted']?>" size="30">First Name:
<input name="firstName" type="text" value="<?php echo $row['firstName']?>" size="60">
Last Name:
<input name="lastName" type="text" value="<?php echo $row['lastName'];?>" size="60">
Email:
<input name="email" type="text" value="<?php echo $row['email'];?>" size="60">
Pet's Name:
<input name="petName" type="text" value="<?php echo $row['petName'];?>" size="60">
State:
<input name="state" type="text" value="<?php echo $row['state'];?>" size="15">
Memorial:
<textarea name="memorial" cols="45" rows="3"><?php echo $row['memorial'];?>
<?php }
?>
</table>
</form>
and here is what it submits to, with the update code:
<form name="form1" method="post" action="proc_tribute.php">
<table width="600" border="0" cellspacing="0" cellpadding="6">
<tr align="left">
<td colspan="2">Update Memorial</td>
</tr>
<?php
// Connect to the database
require_once ('../../Connections/mysql_connect.php');
// Get data
// $query = "UPDATE users SET memorial='$memorial' WHERE memID='$memID'";
$query = "UPDATE users SET memorial=\"". $memorial ."\" WHERE memID=\"".$memID."\"";
$result = mysql_query($query);
if (!$result)
{
die(" Query could not be executed.<br>");
}
else
{
?>
<tr>
<td align="right"><?php echo mysql_affected_rows();?> updated successfully.</td>
<td><input name="dateSubmitted" type="text" value="<?php echo $row['dateSubmitted']?>" size="30"></td>
</tr>
< removed repeated form - same as above>
The form is displayed after the update, but the fields are empty and it indicates that 0 records have been updated.
Can anyone spot the problem, please, or tell me how I should go about this?
Thanks,
ksponline
[edited by: jatar_k at 10:55 pm (utc) on Mar. 4, 2004]
[edit reason] edited code dump [/edit]
<td align="right"><input type="hidden" name="memID" value="<?php $_POST['memID'];?>"></td>
and put this on the page with the update code:
// Put variable into something usable
$memID=$_POST['memID'];
but it's not making any difference. I don't understand what I'm doing wrong, or what I should be doing instead...
Thanks,
ksponline
Thanks...
There was a page previous to the others where the ID is entered. When I understand all this, then I'll incorporate a login system. I'm just making it as basic as possible for now.
Thanks again, I worked with it some more in order to pass the value as you said, and changing the hidden field to this format:
<td align="right"><input type="hidden" name="memID" value="<?php echo "$memID"?>"></td>
made the database update successful. Finally! The updated information didn't display as it should, but hopefully I can pinpoint that. The UPDATE is something new for me though.
Thanks so much again!
ksp