This question already has an answer here:
I know this probably has a very easy fix,but I have been searching around for hours,looking for a solution,only to have nothing.Please don't mark this as a duplicate simply because of the title.bind_param calling to a non-object is usually a syntax error,not an easy fix error.
Code for connect.php:
<?php
$db = new mysqli('127.0.0.1', 'root', '', 'mon');
if($db->connect_errno) {
echo "<p id='gotem'>Something has gone wrong.Tell J to fix it.</p>";
}
?>
Code for user_add.php:
<?php
require_once 'connect.php';
if(!empty($_POST)) {
if(isset($_POST['username'], $_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if(!empty($username) && !empty($password)) {
$insert = $db->prepare("INSERT INTO 'user' ('name', 'pass') VALUES (?, ?)");
$insert->bind_param('ss', $username, $password);
if (!$insert->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
}
}
}
$_SESSION['uid'] = $_POST['username'];
$_SESSION['pss'] = $_POST['password'];
if(!mysqli_query($db_con, $db_query)) {
die('Error:'.mysqli_error($db_con));
}
header("Location: index.php");
?>
</div>