caelin
caelin

Reputation: 246

No output when using mysqli_stmt_bind_param

I am trying to insert data into my MySQL database. All I get is an empty page and no error.

My index.php:

<?php include 'header.php';
      include 'functions.php'?>
<body>
<form role="form" action="ins-user.php" method="post">
  <div class="form-group">
    <label for="mName">Username</label>
    <input type="text" class="form-control" id="mName" placeholder="Enter username" style="width: 45%">
  </div>
  <div class="form-group">
    <label for="mPass">Password</label>
    <input type="password" class="form-control" id="mPass" placeholder="Password" style="width: 45%">
  </div>
  <div class="form-group">
      <label for="eMail">E-Mail</label>
      <input type="email" class="form-control" id="eMail" placeholder="Enter E-Mail" style="width: 45%">
  </div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</body>
</html

>

And here is my ins-user.php:

<?php
include 'header.php';
include 'functions.php';
$sql = "INSERT INTO my_db.test_table (mName,mPass,eMail) VALUES(?,?,?)";

$stmt = mysqli_prepare($con, $sql);

mysqli_stmt_bind_param('sss',
  $_POST['mName'],
  password_hash($_POST['mPass'), PASSWORD_DEFAULT),
  $_POST['eMail']
);

if (!mysqli_stmt_execute($con,$stmt)) {
  die('Error: ' . mysqli_error($con));
}
    echo "User added!";

mysqli_close($con);
?>

I don't even get the "Error: ..." I also checked for changes in my database, but no success. Can someone see the mistake??

Upvotes: 0

Views: 102

Answers (1)

GolezTrol
GolezTrol

Reputation: 116200

For the procedural version of mysqli_stmt_bind_param, the first parameter should be the statement. Thus says the docs.

That function also returns a boolean, which is probably false in your case.

if (!mysqli_stmt_bind_param(
      $stmt,
      'sss',
      $_POST['mName'],
      password_hash($_POST['mPass'), PASSWORD_DEFAULT),
      $_POST['eMail'])) 
{
  // If you get here, binding the parameter failed.
  die("Binding failed");
}

Upvotes: 1

Related Questions