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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.