I'm trying to insert some data into a mysql table but the process doesnt go through and I get nothing printed for the error. I don't think I'm outputting the errors correctly. Looking at php.net it seems like I'm doing the error handling properly but maybe I'm missing something.
Here is the code
$db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$sqlInsert = $db->query("INSERT INTO transactions(`user_id`, `courses`, `invoice`, `start_date`, `end_date`, `mc_gross`, `email`) VALUES ('".$user_id."','".$trim."','".$invoice."','".$start_date."','".$end_date."', '".$email."')");
if($sqlInsert)
{
echo "Inserted successfully";
}
else
{
printf("Error: ", $db->error);
}
The values for the variables are as follows
$custom = $_SESSION['custom'];
$user_id = $_POST['userID'];
$pwd = $_POST['password'];
$email = $_POST['email'];
$start_date = date('Y-m-d');
$end_date = date (('Y-m-d'), strtotime('+120 days'));
$invoice = date('Ymd'). mt_rand(1252,10000);
$invoice_check = $db->query("SELECT `invoice` FROM `transactions` WHERE `invoice` = $invoice");
while ($rows = $invoice_check->fetch_assoc())
{
$invoice = date('Ymd'). mt_rand(1252,10000);
}
$mc_gross = $_SESSION['subtotal'];
$trim = rtrim($custom, ",");
the var_dump for $trim is string(17) "bio_01,calculus_01" and the other variables just echo out normally as you'd expect.
Any ideas?
EDIT Updated the code with $db instead of $sqlInsert. Still no output for an error.
courses$sqlInsertisfalse, you obviously can't use$sqlInsert->error, becausefalseis not an object. You have to use$db->error.Column count doesn't match value count.