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
https://forums.phpfreaks.com/topic/280109-mysqli-bind-parameters-error/
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

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.

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.

@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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.