Jump to content

Using PDO my update scripts runs but does not update. No error.


vandero

Recommended Posts

[code]
<html>
<body>
<?php
include('connect.php');
$ud_NUMB=(int)$_POST["fNumb"];
$ud_PAID=$_POST["fPaid"];
echo $ud_NUMB;
echo $ud_PAID;
$sql = "UPDATE Teams SET Paid = :paid 
                  WHERE Numb = :numb";
$stmt = $db->prepare($sql);                                  
$stmt->bindParam(':paid', $_POST['fPaid'], PDO::PARAM_STR);       
$stmt->bindParam(':numb', $_POST['$fNumb'], PDO::PARAM_STR);    
$stmt->execute();
echo "\nPDO::errorCode(): ";
print $stmt->errorCode();
?>
</br><p><a href='game.php'><H3>Back to main page</H3></a>
</body>
</html>
[/code]

My connect works fine, used in other scripts.  $db is the connection.  My echo of the two passed variables works fine.

 

Example reply from echo is:   8Yes  (didn't bother to put in spaces).  The only reply on error is: PDO::errorCode(): 00000

 

I get the prompt to return to the website link at the end.  No other error codes.

 

But it does not update my record.  It should change record with unique ID of 8 to show Yes in the Paid column.

 

Can someone point me in the right direction here?

 

Thanks

 

 

 

 

 

thanks for replying ginerjm.

 

My Numb field is integer.  My Paid field is varchar.

 

I tried to echo the array $stmt which got my the string conversion error of course.  I tried several other ways that I could think, using[$stmnt] and using the double then single quote with the period but kept getting an error.  I think it should return a true or false if it worked or not, but cannot figure out to echo that return. 

 

I am thinking that I will try and put in the variables $ud_PAID and $ud_NUMB instead of the passed value using $_PAID.  But that shouldn't matter as far I have read.

 

 

GOT IT!  I replaced the $_POST part with the assigned variable $ud_ part and it worked.  But in the PHP manual it shows syntax examples of using $_POST in the line itself.  So why does it work when I assign  it to a variable but not when I put it directly in the statement.

 

so $stmt->bindParam(':paid', $_POST['fPaid'], .....

became $stmt->bindParam(':paid', $ud_PAID, ....  And it works.

 

Thanks

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.