-4

I'm working on a school project and when I'm trying to make a website with registration function it shows this error after I submit the form:

Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in /storage/ssd5/928/6222928/public_html/04_Registration.php:34 Stack trace: #0 {main} thrown in /storage/ssd5/928/6222928/public_html/04_Registration.php on line 34

<!DOCTYPE HTML>
<html>
<head>
  <title>Register Form</title>
</head>

<body>
 <form action="04_Registration.php" method="POST">
   <table>
       <tr>
        <td>Name :</td>
        <td><input type="text" name="username" required></td>
       </tr>
       <tr>
        <td>Password :</td>
        <td><input type="password" name="password" required></td>
       </tr>
       <tr>
        <td>TP Number :</td>
        <td><input type="text" name="tpnumber"></td>
       </tr>
       <tr>
        <td>Gender :</td>
        <td>
          <input type="radio" name="gender" value="m" required> Male
          <input type="radio" name="gender" value="f" required> Female
        </td>
       </tr>
       <tr>
        <td>Group :</td>
        <td>
          <input type="radio" name="group" value="a" required> A
          <input type="radio" name="group" value="b" required> B
        </td>
       </tr>
       <tr>
        <td>Email :</td>
        <td><input type="email" name="email" required placeholder="TP011111@mail.apu.edu.my"></td>
       </tr>
       <tr>
        <td>Phone no :</td>
        <td>
          <select name="phoneCode" required>
            <option selected hidden value="">Select code</option>
             <option value="011">011</option>
             <option value="012">012</option>
             <option value="016">016</option>
             <option value="017">017</option>
             <option value="018">018</option>
             <option value="019">019</option>
          </select>
          <input type="phone" name="phone" required placeholder="017460****">
         </td>
       </tr>
       <tr>
        <td><input type="submit" value="Submit"></td>
       </tr>
    </table>
  </form>
</body>

</html>
    <?php

$username = $_POST['username'];
$password = $_POST['password'];
$tpnumber = $_POST['tpnumber'];
$gender = $_POST['gender'];
$group = $_POST['group'];
$email = $_POST['email'];
$phoneCode = $_POST['phoneCode'];
$phone = $_POST['phone'];
if (!empty($username) || !empty($password) || !empty($tpnumber) || !empty($gender) || !empty($group) || !empty($email) ||
!empty($phoneCode) || !empty($phone)) {
$host = "localhost";
$dbUsername = "id6222928_apuassignment2018";
$dbPassword = "joeshern123";
$dbName = "id6222928_registered";
    //create connection
    $conn = new mysqli($host, $dbUsername, $dbPassword, $dbName);
    if (mysqli_connect_error()) {
     die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
    } else {
     $SELECT = "SELECT email From users Where email = ? Limit 1";
     $INSERT = "INSERT Into users (username, password, tpnumber, gender, group, email, phoneCode, phone) values(?, ?, ?, ?, ?, ?, ?, ?)";
     //Prepare statement
     $stmt = $conn->prepare($SELECT);
     $stmt->bind_param("s", $email);
     $stmt->execute();
     $stmt->bind_result($email);
     $stmt->store_result();
     $rnum = $stmt->num_rows;
     if ($rnum==0) {
      $stmt->close();
      $stmt = $conn->prepare($INSERT);
      $stmt->bind_param("ssssssii", $username, $password, $tpnumber, $gender, $group, $email, $phoneCode, $phone);
      $stmt->execute();
      echo "Registration success!!";
     } else {
      echo "Someone already register using this email";
     }
     $stmt->close();
     $conn->close();
    }
} else {
 echo "All field are required";
 die();
}

?>
YGOPRO
  • 11
  • 3
  • 3
    Please post the relevant part of your PHP source code here on Stack Overflow. The link you've provided doesn't even work for me. See: [How to create a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve). – sɐunıɔןɐqɐp Jun 18 '18 at 06:44
  • 1
    Edit your post to include code for `04_Registration.php` as well –  Jun 18 '18 at 06:45
  • 3
    Possible duplicate of [Fatal error: Call to a member function bind\_param() on boolean](https://stackoverflow.com/questions/27394710/fatal-error-call-to-a-member-function-bind-param-on-boolean) – Bart Friederichs Jun 18 '18 at 06:48
  • 2
    Did you even try to Google your error message? Literally the first hit gives you the answer. – Bart Friederichs Jun 18 '18 at 06:48
  • Posted the .php codes. – YGOPRO Jun 18 '18 at 06:51
  • I'm actaully new to this .php code and not famillar with. I've been googled like hours but I still couldn't understand what's going on. – YGOPRO Jun 18 '18 at 06:52
  • 2
    iirc, depending on your mysql version, `group` is a reserved name, thus encapsulate them with backticks – Kevin Jun 18 '18 at 06:52
  • 1
    and thus your query fails, so my advice to you is first to turn on error reporting and don't forget to use `->error` so that you could see whats going on, debugging is part of a developers life – Kevin Jun 18 '18 at 06:53
  • Nvm, I've fixed. The problem is the $group, after I've changed that it's running smoothly. – YGOPRO Jun 18 '18 at 10:32

2 Answers2

0

Try change this:

bind_param("ssssssii", $username, $password, $tpnumber, $gender, $group, $email, $phoneCode, $phone);

to this:

bind_param($username, $password, $tpnumber, $gender, $group, $email, $phoneCode, $phone);
Gabor
  • 536
  • 5
  • 14
0

Firstly, I hope you're running the program as it is expected via XAMPP.

And usually, this problem occurs because of the code associated with the database,

Perhaps the column name you made in phpmyadmin is different than the column name which you are firing, maybe the mistake would be as little as the spelling of the columnNames or the tableName,

Try checking the same or do some tweaking.

EnthuCoder
  • 37
  • 6