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(); ?> Link to comment https://forums.phpfreaks.com/topic/276812-mysqli-prepared-inserts/ Share on other sites More sharing options...
mac_gyver Posted April 11, 2013 Share Posted April 11, 2013 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. Link to comment https://forums.phpfreaks.com/topic/276812-mysqli-prepared-inserts/#findComment-1424113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.