PDO data entry, doesn’t it work?

Asked

Viewed 76 times

0

I am trying to create a registration page with PDO however, it does not perform the insertion and does not present error, which can be?

include "../pages/sqlconn.php";

$name  = $_POST["name"];
$email = $_POST["email"];
$pass  = $_POST["password"];

try {
    $sql = "INSERT INTO db_user(user_name, user_email, user_pass) VALUES (?,?,?)";
    $ins = $conn->prepare($sql);
    $ins->bindParam(1, $name, PDO::PARAM_STR);
    $ins->bindParam(2, $email, PDO::PARAM_STR);
    $ins->bindParam(3, $pass, PDO::PARAM_STR);
    $ins->execute();
    echo $ins->execute();       
} catch (PDOException $e) {
    echo "ERROR: ".$e->getMessage();
}
  • Gives a var_dump($e); and put here.

  • The page has turned white yet, returned no results...

  • Why, so he’s not entering the Exception, give a var_dump($ins->execute()); and pole here.

  • C: wamp64 www Mysqli-Learn action createAccount.php:25:Boolean false

  • In place of echo $ins->execute(), place print_r($conn->errorInfo());

  • Returned one, Array ( [0] => 00000 [1] => [2] => )

  • Gor, replace VALUES (?,??) with VALUES (:name, :email, :pass) and instead of 1, 2, and 3, in bindParam, replace with :name, :email, and :pass in their proper order and see if there is an error.

  • 1

    Add $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); right after creating the object $conn that will probably appear the error message. I tested the code here and it worked perfectly. The table name is db_user same or would be db_users?

  • Anderson Carlos Woss, that’s right bro, they returned that it was missing a column to have insertion, then I set it in the database as NULL, now functional he entered correctly.

Show 4 more comments

1 answer

-1

Try it like this:

include "../pages/sqlconn.php";

$name  = $_POST["name"];
$email = $_POST["email"];
$pass  = $_POST["password"];

try {
    $sql = "INSERT INTO db_user (user_name, user_email, user_pass) VALUES ('$name','$email','$pass')";
    $conn->query($sql)->fetchAll();       
} catch (PDOException $e) {
    echo "ERROR: ".$e->getMessage();
}
  • Fatal error: Call to a Member Function fetchAll() on Boolean

  • @Igordonizete posts the code of sqlconn.php kindly.

  • <?php&#xA;&#xA;define("HOST", "localhost");&#xA;define("USER", "root");&#xA;define("PASS", "");&#xA;define("DB", "db_teste");&#xA;&#xA;try {&#xA; $conn = new PDO("mysql:host=".HOST.";dbname=".DB, USER ,PASS);&#xA;} catch (PDOException $e) {&#xA; echo "ERROR: ".$e->getMessage();&#xA;}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.