# Bind Statement Error

**URL:** <https://www.phphelp.com/t/bind-statement-error/32371>\
**Category:** Beginners - Learning PHP\
**Created:** [August 13, 2020, 9:14am UTC](https://www.phphelp.com/t/bind-statement-error/32371 "2020-08-13T09:14:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![steveb1471](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/8edcca/32.png) [@steveb1471](https://www.phphelp.com/u/steveb1471)\
**Post date:** [August 13, 2020, 9:14am UTC](https://www.phphelp.com/t/bind-statement-error/32371/1 "2020-08-13T09:14:44Z")

</div>

Hi

I am learning as many of us are and i have come across something that has stumped me for a few days as was wondering if anyone could help.

the below code is throwing a error. I think its around the “insert into” section or where i bind paramiters but could be wrong. Could any help?

```
<?php
$dBServername = "localhost";
$dBUsername = "root";
$dBPassword = "";
$dBName = "loginsystemtut";

// Create connection
$conn = mysqli_connect($dBServername, $dBUsername, $dBPassword, $dBName);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

    if(isset($_POST['insert']))
    {
      $name = $_POST['name'];
      $gender = $_POST['gender'];

      $sql = "INSERT INTO asdf (name,gender) values ($name, $Gender);";
      $stmt = mysqli_stmt_init($conn);
      if (!mysqli_stmt_prepare($stmt, $sql)) {
          // If there is an error we send the user back to the signup page.
        header("Location: ../permnew1.php?error=sqlerror");
        exit();
      }
      else {

      mysqli_stmt_bind_param($stmt, "ss", $name, $gender);
      mysqli_stmt_execute($stmt);
   

      if (!mysqli_stmt_prepare($stmt, $sql)) {
        echo "New record created successfully";
      } 
      else 
      {
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
      }
    }
  }
?>

```

Below is the code for the form

> \<?php

> require “header.php”;  
> ?\>
> 
> ```
> <main>
> <div class="wrapper-main">
> <section class="section-default">
> <h1>Signup</h1>
> <?php
>       
> if (isset($_GET["error"])) {
> if ($_GET["error"] == "emptyfields") {
> echo '<p class="signuperror">Please Fill In All Fields!</p>';
> }
> }
>       
> ?>
> <form class="form-add" action="" method="post">
> <label>Name</label><br>
> <input type="text" name="name" placeholder="name"><br>
> 
> <LABEL>Gender</LABEL><br>
> <select name="gender">
> <option value="">--Select--</option>
> <option value="Male">Male</option>
> <option value="Female">Female</option>
> </select><br>
> 
> <input type="submit" name="insert" value="Insert Data">
> </form>
> </section>
> </div>
> </main>
> 
> ```

---

<div class="post-metadata">

**Author:** ![skawid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@skawid](https://www.phphelp.com/u/skawid)\
**Post date:** [August 13, 2020, 9:16am UTC](https://www.phphelp.com/t/bind-statement-error/32371/2 "2020-08-13T09:16:24Z")

</div>

Can you include the error you’re getting in your question?

---

<div class="post-metadata">

**Author:** ![steveb1471](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/8edcca/32.png) [@steveb1471](https://www.phphelp.com/u/steveb1471)\
**Post date:** [August 13, 2020, 9:17am UTC](https://www.phphelp.com/t/bind-statement-error/32371/3 "2020-08-13T09:17:55Z")

</div>

thanks for the quick reply

Its not giving me a error as such, its just directing me to permnew1.php?error=sqlerror") which is what i set to do if there was a error

---

<div class="post-metadata">

**Author:** ![act78723](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@act78723](https://www.phphelp.com/u/act78723)\
**Post date:** [August 13, 2020, 10:50am UTC](https://www.phphelp.com/t/bind-statement-error/32371/4 "2020-08-13T10:50:55Z")

</div>

> [@steveb1471](#):
>
> if(isset($\_POST[‘insert’]))  
> {  
> $name = $\_POST[‘name’];  
> $gender = $\_POST[‘gender’];
> 
> $sql = “INSERT INTO asdf (name,gender) values ($name, $Gender);”;

$gender and $Gender are not the same and is probably causing your error

---

<div class="post-metadata">

**Author:** ![steveb1471](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/8edcca/32.png) [@steveb1471](https://www.phphelp.com/u/steveb1471)\
**Post date:** [August 13, 2020, 11:12am UTC](https://www.phphelp.com/t/bind-statement-error/32371/5 "2020-08-13T11:12:12Z")

</div>

Hi

Really appreciate the reply

I have changed the case as you suggested to make sure it all is correct but still no change.

does anything else spring to mind?

Thanks

---

<div class="post-metadata">

**Author:** ![act78723](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@act78723](https://www.phphelp.com/u/act78723)\
**Post date:** [August 13, 2020, 12:02pm UTC](https://www.phphelp.com/t/bind-statement-error/32371/6 "2020-08-13T12:02:20Z")

</div>

I’m not familiar with mysqli as I use the much simpler pdo, which I suggest you look into. Hopefully, someone with mysqli experience will be along soon to help you further.

Also, if continuing to use mysqli, place this line before connecting to the db server

`mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);`

---

<div class="post-metadata">

**Author:** ![skawid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@skawid](https://www.phphelp.com/u/skawid)\
**Post date:** [August 13, 2020, 2:29pm UTC](https://www.phphelp.com/t/bind-statement-error/32371/7 "2020-08-13T14:29:45Z")

</div>

Make your code actually log the error somewhere, then you’ll be able to see what’s wrong.

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [August 13, 2020, 2:54pm UTC](https://www.phphelp.com/t/bind-statement-error/32371/8 "2020-08-13T14:54:29Z")

</div>

The OP solved this on a different forum, about 3 hours ago.
