wright67uk Posted April 11, 2013 Share Posted April 11, 2013 Hi, I'm new to MySQLi and I'm trying to do a basic insert into my database. I've checked the first part of my script and I'm connecting fine. I've also echoed $mysqli->host_info . "\n"; and everything is as it should be. The below php gives me an error; Fatal error: Call to undefined method mysqli::bind_param() Why is this? and how can I change my code so that I can do the insert without error? Many thanks. <?php define('HOST', '###'); define('USERNAME', '###'); define('PASSWORD', '###'); define('DB', '###'); $mysqli = new mysqli(); $mysqli->connect(HOST, USERNAME, PASSWORD, DB); $name = "nametest";//$_POST['name']; $year = 2018; //$_POST['year']; $month = "jan"; //$_POST['month']; $wins = 5; //$_POST['wins']; if ($mysqli->connect_errno) { printf("Connect failed: %s\n", $mysqli->connect_error); exit(); } $mysqli->prepare("INSERT INTO `compare` VALUES ('?','?','?','?');"); $mysqli->bind_param("sisi", $name, $year, $month, $wins); $mysqli->execute(); $mysqli->close(); ?> Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 11, 2013 Share Posted April 11, 2013 (edited) when you successfully prepare a query, it returns an instance of the mysqli_stmt class. mysqli_stmt mysqli::prepare ( string $query ) Return Valuesmysqli_prepare() returns a statement object or FALSE if an error occurred. bind_param is a method of the mysqli_stmt class, not a method of the mysqli class. there are excellent examples in the php.net mysqli documentation. Edited April 11, 2013 by mac_gyver 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.