Need help with prepare statement

You guys were right all along i made the variable $session_id = session_start(); But ofc that’s wrong and it shoulda been:

$session_id = $_SESSION['id'];

Now my selected rows are showing a correct number now i just need to echo it out ^^.

Thanks for your help guys as always! :slight_smile:


PDO doesn’t have procedural. Only mysqli_* does. Now, judging your snippet, typically the query will fail whenever you have one of the below.

  • Your query string has a typo some where. Either the columns you specified or your intent was to append a variable name to the prepared statement, but the variable name has a typo or misspelling some where (->bind_param, ->execute, ->store_result, ->num_rows, ->bind_result)
  • The column you specified does not actually exist or it was named differently. Make sure all columns and table are exact.
  • Your client input value does not meet your data structure standards. Say you are selecting id from the database and putting it in the WHERE clause. If the id is not a numeric character, it will be turned into a 0 and your query will fail.

Hello jimmyjolling,

Are you still unable to retrieve your records when using the prepared statement?
If so, I would like to point out another thing that I have noticed.

Pay attention to the line where you bind the parameters with the values. You are still passing in “ssi” first.
In that case, the query would result in:

SELECT * FROM costs 
WHERE costdate BETWEEN 'ssi' AND $date1_raw AND userid=$date2_raw 
ORDER BY costdate

Try removing the “ssi” from the bind_param function call and see if that will work.

Wrong. ssi is the data types for each place holder. Only mysqli_* requires this.

s = string
i = integer
b = blob
d = double

So OP is combining all 3 data types for all 3 place holders, hence why you see ssi. In turn, it’s “string, string, integer”. Just like the OP wanted it to be.

If it were what you are proposing, then you have a hanging variable ($session_id). This is entirely incorrect anyways.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.