I'm working on a project for a buddy of mine and we want to write our database calls in mysqli. I'm new to this and I've only used mysql commands which I know are out of date at this point. I keep getting Call to a member function query() on a non-object on line 30
which is my if ($mysqli->query($sql)) {
command. Could anyone please point me in the right direction for this? I've tried looking it up in W3 schools. Here is my entire code:
// If the form is submitted, INSERT into table.
if (isset($_POST["submit"])) {
// Define $username and $password.
$username = $_POST['user_username'];
$password = $_POST['user_password'];
// Protect them from MySQL injection.
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysqli_real_escape_string($db, $username);
$password = mysqli_real_escape_string($db, $password);
$password = md5($password);
// Run some queries.
if ($_FILES["user_image"]["error"] > 0) {
//Bad Output for form results red text
echo "<font size = '5'><font color=\"#e31919\">Error: NO CHOSEN FILE <br />";
echo"<p><font size = '5'><font color=\"#e31919\">INSERT TO DATABASE FAILED";
} else {
move_uploaded_file($_FILES["user_image"]["tmp_name"],"uploads/" . $_FILES["user_image"]);
$file="uploads/".$_FILES["user_image"];
$image_title = addslashes($_REQUEST['user_image']);
$sql="INSERT INTO users (user_fname, user_lname, user_image, user_phone, user_cell, user_email, user_username, user_password) VALUES ('$_POST[user_fname]', '$_POST[user_lname]', '$_POST[user_image]', '$_POST[user_phone]', '$_POST[user_cell]', '$_POST[user_email]', '$username', '$password')";
if ($mysqli->query($sql)) {
die('Error: ' . $mysqli->error);
}
//Good Output for form results green text
echo '
<form enctype="multipart/form-data" action="insert_image.php" method="post" name="changer">
<div style="padding:10px;">
<h2 style="font-size: 28px;">Success!</h2>
<p style="font-size: 18px;">Your file has been successfully uploaded!</p>
</div>
</form>';
}
}
Thanks!