Table Not Updating

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Table Not Updating

Post by PastorHank »

I am able to retrieve the data I need and create and populate the following, all these fields populate with the correct data

Code: Select all

$fawn_id=$ID;

echo "<form action='updatefawns.php' method=post>"; 
echo "<font color='#6F3700'><b>    Record ID </b></font>";
echo "<input type=text name='$deerid' size='5' maxlength='6' READONLY value='$fawn_id'><br>";
echo "<font color='#6F3700'><b>      Fawn ID </b></font>";
echo "<input type=text name='$fawnnumber' size='25' maxlength='25' READONLY value='$deernumber'><br>";
echo "<font color='#6F3700'><b>          Sex </b></font>";
echo "<input type=text name='$fawns_sex' size='2' maxlength='1' value='$sex_of_fawn'><br>";
echo "<font color='#6F3700'><b>Date Of Birth </b></font>";
echo "<input type=text name='$fawns_date_of_birth' value='$dateofbirth'><br>";
echo "<font color='#6F3700'><b>  Fawn Status </b></font>";
echo "<input type=text name='$fawns_status' size='2' maxlength='1'  value='$statusofdeer'><br>";

echo "<input type=submit value=submit>";
echo "</form>";
the form appears correctly and I am able to edit the fields I need to update.

My 'updatefawns.php' script is as follows

Code: Select all

$fawnstatus = strip_tags(trim($_POST['fawns_status']));
$fawn_to_use=strip_tags(trim($_POST['fawnnumber']));
$fawn_id = $_POST['deerid'];

  $host="localhost"; 
   $user="username";
   $password="password" ;
   $connection = mysql_connect($host,$user,$password) 
        or die("Couldn't Make the Connection"); 
  
 $database="thunde9_thunderhill";
   $db = mysql_select_db($database,$connection)
   	 or die("Couldn't Select Database");   

   $query="UPDATE fawns SET statusofdeer = '$fawnstatus'
   WHERE ID = '$fawn_id' LIMIT 1" ;
   
$result = mysql_query($query)
		or die ("Couldn't Execute Query.");
It seems to work - at least I don't get any error message, but when I look at the records in mysql query browser the record has not been updated. What do I have messed up in my UPDATE statement?


User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

add this piece to the end of your script:

Code: Select all

var_dump($query, mysql_error());
for debugging purposes
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Post by PastorHank »

It gave me
string(60) "UPDATE fawns SET statusofdeer = '' WHERE ID = '' LIMIT 1" string(0) ""
Does that mean, my field values are not being passed?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Does that mean, my field values are not being passed?
Looks like they aren't.
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Post by PastorHank »

That's disturbing. I've read and reread the code and I can't see anything that would be throwing it off...any suggestions?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

var_dump($_POST, $_GET, $_REQUEST, $_SERVER); at the start of your script may reveal something...
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Post by PastorHank »

found the problem it was the

Code: Select all

name='$fawnnumber'
Once I removed the $ things worked fine - talking this stuff out really helps

Thanks
Post Reply