Can you see where i am missing a variable in prepared statement

i am getting an error in my query ‘Warning: mysqli_stmt::bind_param(): Number of variables doesn’t match number of parameters in prepared statement in’

 //query based on the lat long
    $query_weather = "Select id, met_forecast.latitude,met_forecast.longitude, ( 3959 * acos( cos( radians('?') ) * cos( radians( met_forecast.latitude ) ) * cos( radians( met_forecast.longitude ) - radians('?') ) + sin( radians('?') ) * sin( radians( met_forecast.latitude ) ) ) ) AS distance From met_forecast
     HAVING distance < 5  ORDER BY distance Limit 0,1";
    // Setup parameter to be bound into query
    //we've already set this in the above query
    // Get instance of statement
    $stmt_met = $gbgconn->stmt_init();
    // Prepare Query
      // Bind Parameters
      $stmt_met->bind_param("sss",$lat,$lng,$lat );

I can’t for the life of me see where i need to add an extra variable? i have 3 variable and i’ve added 3 ?s to the query. any ideas? is it something really stupid i am missing?

any help appreciated

Just a quick, naive, observation: you are passing 4 parameters:

  1. “sss”
  2. $lat
  3. $lng
  4. $lat

Sorry i don’t understand 1. is the type of variable i am passing though for 2,3 and 4 isn’t it? Did have them as ‘i’ but tried ‘S’ to see if the lat/long were causing an issue.

Hi Noppy,

The single quote marks around your placeholders are what’s causing the error. See this comment in the manual:

doh! now i feel stupid :smile:
would have sworn i’d tried removing them and it didn’t work. Must have not done something right when i tried that, perhaps i missed the quotes on 1 of the variables. All working now. saved me a fair bit of head scratching

Thanks so much

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