0

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??

1

1 Answer 1

1

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");
}
Sign up to request clarification or add additional context in comments.

2 Comments

What do you mean with Start Worrying?? Because even if I copy and paste your text over my text i get zero output
Sorry, that comment was a bit confusing maybe. I meant, that is the point that is only reached when binding fails. How you want to handle that situation is up to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.