rondog Posted August 30, 2007 Share Posted August 30, 2007 does anyone know why this insert statement isnt inserting anything into the data base? $date = date("m-d-y"); $datequery = "INSERT INTO users timelogged VALUES $date WHERE username = '$uname'"; $rundate = mysql_query($datequery); echo $datequery; returns INSERT INTO users timelogged VALUES 08-30-07 WHERE username = 'abarter' so that sounds right to me..i dunno i might be crazy does the timelogged field in the DB have to be something specific? I have it set as VARCHAR right now Quote Link to comment https://forums.phpfreaks.com/topic/67333-solved-query-not-inserting-to-db/ Share on other sites More sharing options...
curtis_b Posted August 30, 2007 Share Posted August 30, 2007 try adding the database name and putting the date in quotes. Varchars need quotes. INSERT INTO databasename.users timelogged VALUES '08-30-07' WHERE username = 'abarter' Quote Link to comment https://forums.phpfreaks.com/topic/67333-solved-query-not-inserting-to-db/#findComment-337810 Share on other sites More sharing options...
rondog Posted August 30, 2007 Author Share Posted August 30, 2007 users.timelogged? I dont think ive seen table.column before. Anyway I tried it and no luck Quote Link to comment https://forums.phpfreaks.com/topic/67333-solved-query-not-inserting-to-db/#findComment-337814 Share on other sites More sharing options...
Ken2k7 Posted August 30, 2007 Share Posted August 30, 2007 Don't think it's the varchar problem unless it's not long enough to hold the value submitted. But what's wrong is the VALUES $date part. You have to tell the database to input date into what table field. Something like this: <?php $date = date("m-d-y"); $datequery = "INSERT INTO users timelogged VALUES date='$date' WHERE username = '$uname'"; $rundate = mysql_query($datequery) or die(mysql_error()); ?> Also try to put in die methods Quote Link to comment https://forums.phpfreaks.com/topic/67333-solved-query-not-inserting-to-db/#findComment-337815 Share on other sites More sharing options...
rondog Posted August 30, 2007 Author Share Posted August 30, 2007 the insert statment goes like this though... INSERT INTO table_name (column1, column2) VALUES ('value1','value2') so the date= part on your statement would be wrong. I did add the or die part and got this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'timelogged VALUES 08-30-07 WHERE username = 'abarter'' at line 1 timelogged is my column name and then im just saying put it in the row where username = the person that is logged in Quote Link to comment https://forums.phpfreaks.com/topic/67333-solved-query-not-inserting-to-db/#findComment-337821 Share on other sites More sharing options...
Ken2k7 Posted August 30, 2007 Share Posted August 30, 2007 Oh I see. But don't you mean Update? Are you trying to add data into that specific table cell or replacing it with new data? If you're replacing, use update. Quote Link to comment https://forums.phpfreaks.com/topic/67333-solved-query-not-inserting-to-db/#findComment-337825 Share on other sites More sharing options...
rondog Posted August 30, 2007 Author Share Posted August 30, 2007 bah ur right.. $datequery = "UPDATE users SET timelogged = '$date' WHERE username = '$uname'"; thanks man Quote Link to comment https://forums.phpfreaks.com/topic/67333-solved-query-not-inserting-to-db/#findComment-337829 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.