Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member
    Join Date
    Apr 2016
    Posts
    717
    Member #
    53891
    Liked
    11 times

    prepared statement troubles

    getting the following error

    Fatal error: Call to a member function bind_param() on boolean in C:\wamp64\www\final\addusers.php on line 8

    with such a small amount of code

    PHP Code:
    <?php
    // no need to validate because info is coming from a trusted source
    session_start();

    $con = new mysqli('localhost''root''''pratts_db');

    $stmt $con->prepare("INSERT INTO `users` VALUES(?,?)");
    $stmt->bind_param('s'$_POST['email'], $_POST['password']);
    $stmt->execute();

    ?>

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    $stmt = $con->prepare("INSERT INTO `users` VALUES(?,?)");
    $stmt->bind_param('s', $_POST['email'], $_POST['password']);
    $stmt->execute();
    Expand out so it's easier to read ...

    $stmt = $con->prepare("INSERT INTO `users` VALUES(?,?)");
    $stmt->bind_param('s', $_POST['email']);
    $stmt->bind_param('s', $_POST['password']);
    $stmt->execute();

    Those 's' needs to be the actual column names in the table called 'users'.
    Or in this case they are 1 and 2 (first value, second value)
    I'm not sure what you named your columns, but it would be like this ...

    $stmt = $dbh->prepare("INSERT INTO users (email, password) VALUES (?, ?)");
    $stmt->bindParam(1, $_POST['email']);
    $stmt->bindParam(2, $_POST['password']);
    $stmt->execute();

    You need to use your real column names for (email, password) ... I don't know what they are.

    bind_param VS bindParam ?? not sure if they are the same.

    This describes two methods:
    "named placeholders"
    "positional placeholders"

    PHP: Prepared statements and stored procedures - Manual
    Last edited by mlseim; Apr 23rd, 2018 at 01:51 PM.


  4. #3
    Senior Member
    Join Date
    Apr 2016
    Posts
    717
    Member #
    53891
    Liked
    11 times
    oh i see I was told the s stood for string and so I would be intiger. thanks


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:08 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com