Canadian Posted February 7, 2010 Share Posted February 7, 2010 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 Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted February 7, 2010 Share Posted February 7, 2010 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 Quote Link to comment Share on other sites More sharing options...
Hussam Posted February 7, 2010 Share Posted February 7, 2010 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.