Jump to content

Mysqli Bind Parameters error.


benoit1980

Recommended Posts

Hello,

 

I am having this error, any idea why I did wrong please?

Fatal error: Call to a member function format() on a non-object in /home/account/public_html/vchek/header.php on line 119

 

My code is this one at this line:

<?php
$mysqli = new mysqli("localhost", $username, $password, $db_name);
 
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
 
$stmt = $mysqli->prepare("INSERT INTO $tbl_name (id, date, phone_number, email, code, recommendedby, terms, vipnotifications, name, surname, age, group_leader, department, city) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param($id, $dat_date->format('Y-m-d H:i:s'), $phone_number, $email, $code, $recommendedby, $terms, $vipnotifications, $name, $surname, $age, $group_leader, $department, $city);
 
 
$id = NULL;
$phone_number = real_escape_string($phone_number);
$email = real_escape_string($email);
$code = real_escape_string($code); 
$recommendedby = real_escape_string($recommendedby); 
$terms = real_escape_string($terms);
$vipnotifications = real_escape_string($vipnotifications); 
$name = real_escape_string($name);
$surname = real_escape_string($surname);
$age = real_escape_string($age);
$city = real_escape_string($city);
$group_leader = NULL; 
$department = NULL; 
    
 
/* execute prepared statement */
$stmt->execute();
 
 
?>


 

 

Thank you!

 

Ben

Link to comment
Share on other sites

You need i move your prepare statement to just above your execute statement. The problem is that you are defining variables in the prepare before you actually declare the values of those variables. Plus i see nowhere where you define a value for $tbl_name

Edited by fastsol
Link to comment
Share on other sites

1. You didn't post all your code.

2. real_escape_string() is not a function but a method of mysqli.

3. You didn't post all your code.

4. Don't use it when you're using prepared statements.

5. $dat_date appears to be undefined but I don't know for sure because

6. You didn't post all your code.

Link to comment
Share on other sites

also, your $stmt->bind_param() statement is incorrect. the first parameter needs to be a string consisting of the data types.

 

your series of threads in the forum show a lack of understanding or of just copy/pasting things without understanding what they are. i recommend you slow down and read a good php/mysql book or tutorial or the examples in the php.net documentation.

 

@fastsol, the variables can be defined/assigned values after the bind statement. the variables are bound by reference and are actually evaluated when the ->execute() method is called.

Link to comment
Share on other sites

@fastsol, the variables can be defined/assigned values after the bind statement. the variables are bound by reference and are actually evaluated when the ->execute() method is called.

Interesting, I did not know that.   He still hasn't defined a $tbl_name amongst other things wrong.

Link to comment
Share on other sites

Interesting, I did not know that.   He still hasn't defined a $tbl_name amongst other things wrong.

He probably has, actually. Did you see that the real_escape_string() lines are escaping variables? Those haven't been defined either... as far as the code posted shows. That's why he needs to post the rest of the code.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.