fry2010 Posted February 25, 2009 Share Posted February 25, 2009 <?php session_start(); require_once('bookmark.php'); $user = 'fry2010'; try { $conn2 = db_connect(); $result = $conn2->query("INSERT INTO accountuser (joined) VALUES (CURDATE())"); if(!$result) throw new Exception('error'); } catch(Exception $e) { echo $e->getMessage(); } $conn = db_connect(); $result = $conn->query(" SELECT joined FROM useraccount WHERE username = '$user' "); while($row = $result->fetchObject()) { print $row->joined; } ?> The table has already been filled with a member. It finds the information correctly, but it doesnt perform the INSERT CURDATE() part. So it basically returns the default value which is '0000-00-00'. This is the part that is not inserting: $result = $conn2->query("INSERT INTO accountuser (joined) VALUES (CURDATE())"); I have tried putting the CURDATE() in quotes aswell but still doesnt work. Any ideas? Link to comment https://forums.phpfreaks.com/topic/146944-solved-why-does-this-not-work/ Share on other sites More sharing options...
fry2010 Posted February 25, 2009 Author Share Posted February 25, 2009 I have also tried to use UPDATE instead, and the same thing. It just doesnt want to add to it or change it. Someone must know surely people here put dates into a mysql database? Link to comment https://forums.phpfreaks.com/topic/146944-solved-why-does-this-not-work/#findComment-771447 Share on other sites More sharing options...
samshel Posted February 25, 2009 Share Posted February 25, 2009 try running the query directly in phpmyadmin or any other mysql client u have. Link to comment https://forums.phpfreaks.com/topic/146944-solved-why-does-this-not-work/#findComment-771451 Share on other sites More sharing options...
fry2010 Posted February 25, 2009 Author Share Posted February 25, 2009 aha...that has helped. well it hasnt worked, but it helps by actualy telling me what is incorrect. Thank you. It says 'field username doesnt have a default value...' Ok i added a WHERE clause to select it with a given username. Now it says I have incorrect syntax with my where clause. this: $result = $conn2->query("INSERT INTO useraccount (joined) VALUE (CURDATE()) WHERE username = '$user'"); Link to comment https://forums.phpfreaks.com/topic/146944-solved-why-does-this-not-work/#findComment-771459 Share on other sites More sharing options...
fry2010 Posted February 25, 2009 Author Share Posted February 25, 2009 my fault. I should have used UPDATE as I did originally once I sorted the syntax issue out. Because a default value was given for the table you have to update because you cant insert it. Thanks for the pointer samshel. Link to comment https://forums.phpfreaks.com/topic/146944-solved-why-does-this-not-work/#findComment-771462 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.