1

Having trouble getting the data to insert into Maria DB. While attempting this project I have used about every source I can think of and I'm resorting to posting a question online. Below is my code and the error it produces is "Fatal error: Call to undefined method mysqli::mysqli_prepare() in C:\xampp\htdocs\scripts\insert.php on line 12". Been mulling over this for a couple days and so far I have found nothing at all on youtube or stackoverflow.

<?php
//Set up credentials
$servername = "localhost";
$username = "root";
$password = "";
$database = "test";
$db = new PDO("mysql:host=localhost;dbname=test;","$username","$password");
// Create connection
$link = new mysqli($servername,$username,$password,$database) or                            die($mysqli->error);
$a = $_POST["a"];
$sql = "INSERT INTO ass (asdf) VALUES('$a')"; 
$result = $link->mysqli_prepare($sql);
$stmt  = $database->mysqli_prepare($sql);
$stmt->execute(array($_POST['a']));
$stmt->close();
?>
  • What does the `or` do behind the `new mysqli()` call? That seems a bit off. You also prepare the `$sql` twice, once with `$link->` and once with `$database->`. The second one is certainly wrong. Why not use a good guide to get you started? There are many. Here's one: http://programmerblog.net/php-mysqli-tutorial-for-beginners Never mix mysqli and PDO! – KIKO Software Apr 13 '18 at 23:47
  • This is the code I got after trying everything I got the error before mixing the two. I appreciate the guide I hope it helps – Matt Morrison Apr 14 '18 at 00:56

0 Answers0