Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
  1  <?php
  2  session_start();
  3  include_once("../includes/empty_file.php");
  4  $username = sanitize($_POST["username"]);
  5  $password = encrypt(sanitize($_POST["password"]));
  6  $fullname = sanitize($_POST["fullname"]);
  7  $mobile_no = sanitize($_POST["mobile_no"]);
  8  $user_stat = "verified";
  9  $user_type = "csr";
 10  $kiosk_operator = "1";
 11  $site = "si";
 12  if(isset($_SESSION["ref_id"])){
 13      $ref_id = sanitize($_SESSION["ref_id"]);
 14      $number1 = rand(100,100000);
 15      $t=time();
 16      $myrefid = $number1.$t;
 17      $mobile_no = "CP No.: ".$mobile_no;
 18      $query = $conn->prepare("INSERT INTO tbl_user (user_name, user_password, user_fullname, user_stat, user_type, user_timestamp,  mobile_no,angent_id, kiosk_operator, site) VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP,?,?,?,?);");
 19      $query->bind_param("sssssssss", $username, $password, $fullname, $user_stat, $user_type,$mobile_no,$myrefid,$kiosk_operator,$site);
 20      $query_verify = $conn->prepare("SELECT * from tbl_user where user_name=?");
 21      $query_verify->bind_param("s", $username);
 22      $query_verify->execute();
 23      $result=$query_verify->get_result();
 24      if ($result->num_rows == 0) {
 25      $query_verify_email = $conn->prepare("SELECT * from tbl_user where user_email=?");
 26      $query_verify_email->bind_param("s", $email_add);
 27      $query_verify_email->execute();
 28      $result_email=$query_verify_email->get_result();
 29      $result_query = $query->execute();
 30      echo $result_query;
 31      $query_verify_email->close();
 32  }else{
 34  }
 35  $query_verify->close();
 36  $query->close();
 37  }else{
 38      $number1 = rand(100,100000);
 39      $t=time();
 40      $myrefid = $number1.$t;
 41      $mobile_no = "CP No.: ".$mobile_no;
 42      $query = $conn->prepare("INSERT INTO tbl_user (user_name, user_password, user_fullname, user_email, user_fb, user_timestamp,mobile_no,my_agent_id,angent_id,for_agent) VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP,?,?,?,?,?);");
 43      $query->bind_param("sssssssss", $username, $password, $fullname, $email_add, $facebook,$mobile_no,$ref_id,$myrefid,$for_agent);
 44      $query_verify = $conn->prepare("SELECT * from tbl_user where user_name=?");
 45      $query_verify->bind_param("s", $username);
 46      $query_verify->execute();
 47      $result=$query_verify->get_result();
 48      if ($result->num_rows == 0) {
 49      $query_verify_email = $conn->prepare("SELECT * from tbl_user where user_email=?");
 50      $query_verify_email->bind_param("s", $email_add);
 51      $query_verify_email->execute();
 52      $result_email=$query_verify_email->get_result();
 53      $result_query = $query->execute();
 54      echo $result_query;
 55      $query_verify_email->close();
 56  }else{
 58  }
 59  $query_verify->close();
 60  $query->close();
 61  }
 67  ?>

What I have tried:

pls help with this error,
Fatal error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\public_html\user\register.php on line 43
Updated 10-Jun-23 0:40am
Richard MacCutchan 9-Jun-23 10:26am    
At a guess the call to $conn->prepare on line 42 failed. So you need to do some debugging to find out why.
Member 15627495 9-Jun-23 11:05am    
yes, count again how many args are in the bind-param() declaration , it seems there a overload of args,

read again about bind_param() function.
the fix is close for you.

You have a mismatch in the number of fields specified in the query and the number of parameters provided in the 'bind_param' function. In your case, you have 10 fields specified in the query, but you're providing 11 parameters in the 'bind_param' function as per OriginalGriff's solution stated.

Make sure the number of placeholders in your 'query' and the number of parameters in the 'bind_param' function match exactly, and the data type characters ("s" in your case and only 9 specified) correspond to the correct data types of your respective parameters. Make sure the number of placeholders in the query also matches the number of "s" characters specified in the 'bind_param' function. The correct query and parameter binding should be -
$query = $conn->prepare("INSERT INTO tbl_user (user_name, user_password, user_fullname, user_email, user_fb, user_timestamp, mobile_no, my_agent_id, agent_id, for_agent) VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?, ?, ?, ?);");

$query->bind_param("ssssssssss", $username, $password, $fullname, $email_add, $facebook, $mobile_no, $ref_id, $myrefid, $agentid, $for_agent);

As mentioned above, you can do an error check -
//Check if your $query is returning 'true' or 'false'. If false, show the error why it is false.
if ($query === false) {
    die('Error in preparing the statement: ' . $conn->error);
Share this answer
When conn->prepare fails, it returns false - and then you try to use it as if it succeeded, and the system complains because a boolean value doesn't have a member function called bind_param.

The simplest solution is to check what the prepare call returns, and then if it is false, start looking at your DB and the query to find out why.

To my count, you are tryin g to provide 11 values for ten columns:
INSERT INTO tbl_user (user_name, user_password, user_fullname, user_email, user_fb, user_timestamp,mobile_no,my_agent_id,angent_id,for_agent)  -- !0 columns listed.
VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP,?,?,?,?,?); -- 11 parameters required.
Share this answer
Richard MacCutchan 10-Jun-23 7:38am    
+5; why would someone give that a 1 vote? Pond life I assume.
OriginalGriff 10-Jun-23 8:58am    
I'm being stalked - I suspect Dave and I upset someone just over a week ago by explaining why doing homework for people doesn't help them in the long run.
Ever since then, he's been downvoting everything I post that he can find. Doesn't matter at all - he's very low rep and hasn't realized that his votes carry almost no weight at all! :laugh:

Ignore him - I do.
Andre Oosthuizen 10-Jun-23 7:47am    
Same here, worth of +5!
The most likely cause of this error is that the previous call to $conn->prepare() on line 31 or line 37 returned false instead of a prepared statement object. This can happen if there was an error in the SQL query syntax or if there was a problem with the database connection.

To resolve this issue, you should check the following points:

1. Verify that the database connection ($conn) is established correctly before the prepare() statements. Ensure that the database credentials are accurate and that the connection is successful.

2. Check the SQL query syntax in the prepare() statements on lines 31 and 37. Make sure the table and column names are correct and that the query is properly structured.

3. After calling $conn->prepare(), you should check if the statement preparation was successful before proceeding. You can do this by checking the returned value of $conn->prepare(). If it returns false, you can use $conn->error to get the specific error message from the database.

Hope this will help you to find your actual cause.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900