simpson_121919 Posted January 5, 2014 Share Posted January 5, 2014 I am trying to use a SELECT count(*) to check if a given record exists but its not working and always returns FALSE. I am stumped. At the very least I would think it would return 0. I have checked the SELECT statement in myphpAdmn to make sure that was not the issue. Here is my code - $Qchoice = "SELECT count(*) FROM collect_temp_table WHERE user_ID=:userID AND gID=:gID AND rID=:rid"; $QchoicePreped = $dbh->prepare($Qchoice); $QchoicePreped->bindParam(':userID',$userID,PDO::PARAM_STR,75); $QchoicePreped->bindParam(':gID',$gID,PDO::PARAM_STR,; $QchoicePreped->bindParam(':rID',$rID,PDO::PARAM_STR,3); $QchoicePreped->execute(); $QchoiceResult = $QchoicePreped->fetch(PDO::FETCH_NUM); Any help would be appreciated, thanks. Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted January 5, 2014 Solution Share Posted January 5, 2014 (edited) $QchoiceResult is an array. if you are not referencing $QchoiceResult[0], you won't get the selected count(*) value from the query. edit: you also have a spelling/capitalization error between the :rid placeholder in the query and the bind statement that is either throwing a php warning or an exception, depending on what pdo error mode you are using. you always need to test for errors before you can use the result from any step in your code. Edited January 5, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
simpson_121919 Posted January 5, 2014 Author Share Posted January 5, 2014 That was it, I looked at that code for awhile and did not see that. I think I have been at this too long and need to give my eyes a rest. Thank you for the advice and help. Quote Link to comment 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.