I have a problem with my code. I think it's good but the console says its not:
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/u772833821/public_html/DB_Functions.php on line 66
Here is the code :
$result = mysqli_query($con, "INSERT INTO users SET (email, username, encrypted_password, salt, created_at) VALUES('$email', '$uname', '$encrypted_password', '$salt', NOW())");
Your query is incorrect. Try as below :
$result = mysqli_query($con, "INSERT INTO users (email, username, encrypted_password, salt, created_at) VALUES('$email', '$uname', '$encrypted_password', '$salt', NOW())");
Try to check $con
is valid or not:
$host = "your_host"; // replace these settings for your own
$username = "your_username";
$password = "your_password_if_any";
$db = "your_db_name";
$con = mysqli_connect($host, $username, $password, $db);
if (!$con) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
References:
- http://php.net/manual/en/function.mysqli-connect.php
- http://php.net/manual/en/mysqli.query.php
- http://php.net/manual/en/mysqli.error.php
- http://dev.mysql.com/doc/refman/5.7/en/insert.html
Please follow steps, there are more then one correction:
1. Remove SET from INSERT query
$result = mysqli_query($con, "INSERT INTO users (email, username, encrypted_password, salt, created_at) VALUES('$email', '$uname', '$encrypted_password', '$salt', NOW())");
2. Check connection error
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
if (!$con) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
Perhaps issue with connection. Let me know what is the output from point 2.