Jump to content

Query Question?


Canadian

Recommended Posts

I have a database table that is set up as follows for testing. 

 

Column 1: name = order_id (auto increment), type = int

Column 2: name = email, type = varchar

Column 3: name = zip, type = char

Column 4: name = time, type = timestamp

 

I'm creating a query for the database to insert the users email and zip code into my table.  I think my query should look like this...

 

$query = "insert into orders values ('".$purchase_email."', '".$zip."')";

 

Here are my question.

 

1. Do I have to put a value in my query for "order_id" if it is set to auto increment?

 

2. Do I have to put a value in my query for "time" if it is a timestamp?  My understanding is that time stamp will write a value to this column when the table row is edited. 

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/191218-query-question/
Share on other sites

Answer to 1 no the database automatically inserts it for you.

Answer to 2 you can use now(); but that will return your servers time if your server is not in your timezone you will have to define it with a variable for example

 

date_default_timezone_set('Asia/Bangkok');
$currentdate='';
$currentdate = date('Y-m-d H:i:s');

 

and insert $currentdate

Link to comment
https://forums.phpfreaks.com/topic/191218-query-question/#findComment-1008216
Share on other sites

your questions has been answered correctly, however your query will not work because its wrong.

 

use this one:

 

$query = "insert into orders (email, zip) values ('$purchase_email', '$zip')";

 

dont worry about the concatenation in this case, the query will work this way, no need to litter the code with quotes in this case.

 

By the way, I love people who know how to ask the question like you did lol.

 

good luck!

Link to comment
https://forums.phpfreaks.com/topic/191218-query-question/#findComment-1008262
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.