Reputation: 541
I want the date to be added to an orders table I have created, once the user proceeds to checkout. The code I currently has just prints:
"Error: Column count doesn't match value count at row 1"
Here's my code:
$sql = "INSERT INTO orders (customer_id, total, order_date) VALUES ('$name', '$total', 'DATETIME: Auto NOW()', NOW() )";
The name and total columns store but the date does not. How can I solve this?
Upvotes: 0
Views: 55
Reputation: 37
It looks like you need 3 values: customer_id, total, order_date
but you give 4 :'$name', '$total', 'DATETIME: Auto NOW()', NOW()
Maybe it should look like this:
"INSERT INTO orders (customer_id, total, order_date) VALUES ('$name', '$total', NOW() )";
Upvotes: 0
Reputation: 272
Your error means that you that the number of fields does not match the number of values. That seems correct: your query tries to insert 4 values into 3 fields. You'd probably have to rewrite the query to
$sql = "INSERT INTO orders (customer_id, total, order_date) VALUES ('$name', '$total', NOW() )";
Upvotes: 0
Reputation: 704
You want to insert data inside customer_id, total, order_date (3 rows) but you are sendig '$name', '$total', 'DATETIME: Auto NOW()', NOW(), FOUR.
Upvotes: 0
Reputation: 3101
This way:
$sql = "INSERT INTO orders (customer_id, total, order_date) VALUES ('$name', '$total', NOW())";
Upvotes: 2