benoit1980 Posted July 12, 2013 Share Posted July 12, 2013 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 Quote Link to comment Share on other sites More sharing options...
fastsol Posted July 13, 2013 Share Posted July 13, 2013 (edited) 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 July 13, 2013 by fastsol Quote Link to comment Share on other sites More sharing options...
requinix Posted July 13, 2013 Share Posted July 13, 2013 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. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted July 13, 2013 Share Posted July 13, 2013 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. Quote Link to comment Share on other sites More sharing options...
fastsol Posted July 13, 2013 Share Posted July 13, 2013 @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. Quote Link to comment Share on other sites More sharing options...
requinix Posted July 14, 2013 Share Posted July 14, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.