vandero Posted February 23, 2014 Share Posted February 23, 2014 [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 Quote Link to comment https://forums.phpfreaks.com/topic/286457-using-pdo-my-update-scripts-runs-but-does-not-update-no-error/ Share on other sites More sharing options...
Solution ginerjm Posted February 23, 2014 Solution Share Posted February 23, 2014 Silly ? perhaps but are Num & Paid alphanum fields in the table? And just for grins, test the value of $stmt after the execute is done. Quote Link to comment https://forums.phpfreaks.com/topic/286457-using-pdo-my-update-scripts-runs-but-does-not-update-no-error/#findComment-1470303 Share on other sites More sharing options...
vandero Posted February 23, 2014 Author Share Posted February 23, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/286457-using-pdo-my-update-scripts-runs-but-does-not-update-no-error/#findComment-1470323 Share on other sites More sharing options...
vandero Posted February 23, 2014 Author Share Posted February 23, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/286457-using-pdo-my-update-scripts-runs-but-does-not-update-no-error/#findComment-1470326 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.