i8grand Posted May 25, 2010 Share Posted May 25, 2010 I have the following piece of code that I am using to try and insert a new row of data into a table in my SQL database. Both $customerID and $puzzle are obtained from SESSION variables, and $startGrid is got through the query below. The statement should work but can't work out why it is not! $dbQuery = "SELECT startGrid FROM puzzle WHERE id=$puzzle"; $result = mysql_query($dbQuery,$db); $dbRow = mysql_fetch_array($result); $startGrid = $dbRow[0]; $dbQueryNew = "INSERT INTO puzzlestatus VALUES (NULL, $customerID, $puzzle, $startGrid, Current_Timestamp, NULL)"; $resultNew = mysql_query($dbQueryNew, $db); Any help at all would be greatly appreciated, thanks Dylan. Quote Link to comment https://forums.phpfreaks.com/topic/202836-insert-into-statement/ Share on other sites More sharing options...
-Karl- Posted May 25, 2010 Share Posted May 25, 2010 Echo the query to see if the values there, are what you expect. Quote Link to comment https://forums.phpfreaks.com/topic/202836-insert-into-statement/#findComment-1062998 Share on other sites More sharing options...
i8grand Posted May 25, 2010 Author Share Posted May 25, 2010 yea, Current_Timestamp is wrong! How do I insert the current timestamp in this case. I want it to be in the format of the example 2010-04-15 14:45:18 I know this is another question, sorry. All help again much appreciated Dylan. Quote Link to comment https://forums.phpfreaks.com/topic/202836-insert-into-statement/#findComment-1063002 Share on other sites More sharing options...
-Karl- Posted May 25, 2010 Share Posted May 25, 2010 Wrong how? Quote Link to comment https://forums.phpfreaks.com/topic/202836-insert-into-statement/#findComment-1063004 Share on other sites More sharing options...
i8grand Posted May 25, 2010 Author Share Posted May 25, 2010 when i echo "CURRENT_TIMESTAMP" it simply echoes the words "CURRENT_TIMESTAMP". I need it to echo to show the time and date in the format above. Quote Link to comment https://forums.phpfreaks.com/topic/202836-insert-into-statement/#findComment-1063012 Share on other sites More sharing options...
-Karl- Posted May 25, 2010 Share Posted May 25, 2010 $date = date('Y-m-d H:i:s'); echo $date; That gives the format you require. As for the query, current_timestamp is a MySQL function. So simply echoing CURRENT_TIMESTAMP, will just echo exactly what it says. However, I see no reason for it to not work in the query. Quote Link to comment https://forums.phpfreaks.com/topic/202836-insert-into-statement/#findComment-1063016 Share on other sites More sharing options...
i8grand Posted May 25, 2010 Author Share Posted May 25, 2010 Thanks very much that worked for getting the timestamp working right. Still doesnt seem to insert into my database after the query is executed though! no idea what why.. Quote Link to comment https://forums.phpfreaks.com/topic/202836-insert-into-statement/#findComment-1063027 Share on other sites More sharing options...
-Karl- Posted May 25, 2010 Share Posted May 25, 2010 Are you sure the database is set up correctly and everything looks fine when echoing the query? Quote Link to comment https://forums.phpfreaks.com/topic/202836-insert-into-statement/#findComment-1063029 Share on other sites More sharing options...
i8grand Posted May 25, 2010 Author Share Posted May 25, 2010 The database is set up fine because I can alter already created records. And how exactly do you mean echo the query, I just echoed each attribute that I want to put into the record: echo "$customerID"."$puzzle"."$startGrid"."$date"; is there a way to echo the whole query: $dbQueryNew = "INSERT INTO puzzlestatus VALUES (NULL, $customerID, $puzzle, $startGrid, $date, NULL)"; $resultNew = mysql_query($dbQueryNew, $db); thanks for all your help, its great. Quote Link to comment https://forums.phpfreaks.com/topic/202836-insert-into-statement/#findComment-1063036 Share on other sites More sharing options...
liamloveslearning Posted May 25, 2010 Share Posted May 25, 2010 $dbQueryNew = "INSERT INTO puzzlestatus VALUES (NULL, $customerID, $puzzle, $startGrid, $date, NULL)"; Quote Link to comment https://forums.phpfreaks.com/topic/202836-insert-into-statement/#findComment-1063037 Share on other sites More sharing options...
-Karl- Posted May 25, 2010 Share Posted May 25, 2010 echo $dbQueryNew; Quote Link to comment https://forums.phpfreaks.com/topic/202836-insert-into-statement/#findComment-1063038 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.