Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8231563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:32:10+00:00 2026-06-07T17:32:10+00:00

Hey Guys I’m running this little function here function getBeaches() { $request=Slim::getInstance()->request(); $args=filter_var_array(func_get_args(),FILTER_SANITIZE_STRING); $sql=SELECT

  • 0

Hey Guys I’m running this little function here

function getBeaches() {

$request=Slim::getInstance()->request();

$args=filter_var_array(func_get_args(),FILTER_SANITIZE_STRING); 
$sql="SELECT * FROM beaches WHERE state=:state AND city=:city"; 

    //  var_export($args); die();
    //  array ( 0 => 'wa', 1 => 'seattle', )

try {
    $db         = getConnection();
    $stmt       = $db->prepare($sql);


        $stmt->bindValue('state',   $args[0], PDO::PARAM_STR); //should bind wa 
        $stmt->bindValue('city',    $args[1], PDO::PARAM_STR); //should bind seattle
        $stmt->execute();

    $stmt       = $db->query($sql);
    $beaches    = $stmt->fetchObject();
    $db         = null;

    echo '{"map": ' . stripslashes(json_encode($beaches)) . '}';
} catch(PDOException $e) {
    echo '{"error":{"text":'. $e->getMessage() .'}}';
}

    /* {"error":{"text":SQLSTATE[42000]: Syntax error or access violation: 
     * 1064 You have an error in your SQL syntax; check the manual that  
     * corresponds to your MySQL server version for the right syntax to use 
     * near ':state AND city=:city' at line 1}}
     */

}

And am getting the error I commented at the bottom, trying to run this like so

mysql$ SELECT * FROM beaches WHERE state='wa' AND city='seattle';

May be this rings some bells?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:32:12+00:00Added an answer on June 7, 2026 at 5:32 pm

    You need the semicolons before your param names: (Not 100% true, see edit)

    $stmt->bindValue(':state',   $args[0], PDO::PARAM_STR); //should bind wa 
    $stmt->bindValue(':city',    $args[1], PDO::PARAM_STR); //should bind seattle
    

    From the PHP docs on PDOStatement::bindValue():

    Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form :name. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter.

    EDIT
    As @jeroen has pointed out the problem (the same one in your pastebin) that you overwrite the $stmt variable before you get the data from it. In you code the problem is around the 17th line:

    $stmt->execute();  // $stmt now has query results (from the query with parameters bounded)
    
    $stmt       = $db->query($sql); // You redo the query. Now $stmt has no query results and no parameters are bound
    $beaches    = $stmt->fetchObject(); // Statement assumes you want to execute query and does so but not parameters are bound
    

    You can remedy this by changing the above lines to:

    $stmt->execute();
    $beaches = $stmt->fetchObject();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;
Hey guys I'm running this code in Android: public ServiceServer(String serverName) { this.serverName =
Hey guys this is my html code: <div class=nakupy> <li class=icn_kategorie><a href=#>Nákupy</a> <div class=sub_menu>
hey guys having this really simple problem but cant seem to figure out have
Hey guys I've written this MS SQL script with my awesome MS SQL skills,
Hey guys I'm following the rails tutorial found here http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/ and I've gotten to
Hey Guys I've been struggling with this for the last hour and pouring over
Hey guys I just noticed that my join statement here SELECT * FROM reports
Hey guys I can't seem to get the syntax here right, I'm just trying
Hey guys here is my php: $x = array(one, two, three); foreach ($x as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.