相关文章推荐
傻傻的熊猫  ·  为什么会存在 1px ...·  2 年前    · 
帅气的蚂蚁  ·  xcode - ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I get this error when i'm executing my code. I know this has been discussed a several times here but i couldn't solve my problem by reading the solutions provided there.

This is the error i get: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2031

This is my code:

function insertMarker(){
    $lat = $_POST['lat'];
    $long = $_POST['long'];
    $street = $_POST['street'];
    $city = $_POST['city'];
    $zip = $_POST['zip'];
    echo ("$lat, $long, $street, $city, $zip");
    global $dbconnect;
    $query = $dbconnect->query("INSERT INTO address (latitude, longitude, street, city, zip) VALUES (?,?,?,?,?)");
        $query->bindParam(1, $lat);
        $query->bindParam(2, $long);
        $query->bindParam(3, $street);
        $query->bindParam(4, $city);
        $query->bindParam(5, $zip);
        $query->execute();
        //$query->execute(array(":lat"=>$lat, ":long"=>$long,":street"=>$street,":city"=>$city,":zip"=>$zip));
                If dbconnect is an instance of PDO then query both creates a prepared statement and then executes it all in one go. So its not getting the parameters bound initially. use PDO::prepare instead of PDO::query.
– prodigitalson
                Dec 7, 2014 at 0:10
                Had same problem.  Stupid type-o on my part, but your answer helped point it out.  Thanks.
– a coder
                Jul 29, 2015 at 14:43
    echo ("$lat, $long, $street, $city, $zip");
    global $dbconnect;
    $query = $dbconnect->prepare("INSERT INTO address (latitude, longitude, street, city, zip) VALUES (?,?,?,?,?)");
    $query->bindParam(1, $lat);
    $query->bindParam(2, $long);
    $query->bindParam(3, $street);
    $query->bindParam(4, $city);
    $query->bindParam(5, $zip);
    $query->execute(array(":lat"=>$lat, ":long"=>$long,":street"=>$street,":city"=>$city,":zip"=>$zip));
                You should not use bindParam and then also use the params as the argument to execute, you should use 1 or the other. The params in execute take precedence of those bound with bindParam and it can result in un-bound parameters if there is a difference.
– prodigitalson
                Dec 7, 2014 at 1:18