This question already has an answer here:
$a = "INSERT INTO `uc_messages` (from, to, time, subject, description) VALUES ('q', 'a', CURRENT_DATE(), 'a', 'a')";
$con = mysqli_connect('localhost', '', '');
if(!mysqli_query($con, $a)) { die('Invalid query: ' . mysqli_error($con)); }
This is the code I'm using to insert values into my table, but for some reason this code doesn't work. This is my database and this is the table I'm trying to insert values into. This is the error I get "Invalid query: No database selected" although I include the file that includes the database.
<?php
//Database Information
$db_host = "localhost"; //Host address (most likely localhost)
$db_name = "users"; //Name of Database
$db_user = "root"; //Name of database user
$db_pass = ""; //Password for database user
$db_table_prefix = "uc_";
GLOBAL $errors;
GLOBAL $successes;
$errors = array();
$successes = array();
/* Create a new mysqli object with database connection parameters */
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);
GLOBAL $mysqli;
if(mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
exit();
}
//Direct to install directory, if it exists
if(is_dir("install/"))
{
header("Location: install/");
die();
}
?>
</div>