limitphp Posted November 14, 2008 Share Posted November 14, 2008 Is something wrong with this code? mysql_query("INSERT INTO songcomments (songID, userID, username, comment, date) VALUES ('2', '2', '2', '2', DATE_ADD(NOW())"); I took out all the variables and just replaced them with values to test it. It doesn't seem to be inserting anything in the database. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 14, 2008 Share Posted November 14, 2008 Why aren't you adding any code to test if the query is even working? $query = "INSERT INTO songcomments (songID, userID, username, comment, date) VALUES ('2', '2', '2', '2', DATE_ADD(NOW())"; mysql_query($query) or die ($query.'<br><br>'.mysql_error()); Quote Link to comment Share on other sites More sharing options...
limitphp Posted November 14, 2008 Author Share Posted November 14, 2008 Ok, my other pages aren't working either. Its a wamp server issue. I just set the password and then set it in the config file in wamp/apps/phpadmin2.xx/ is there another place I need to set this password? Setting the password on the test machine just seemed to mess everything up. Quote Link to comment Share on other sites More sharing options...
flyhoney Posted November 14, 2008 Share Posted November 14, 2008 I think DATE_ADD(NOW()) can just be NOW(), but I can't tell you why the query isn't executing. Whenever you need to test SQL, it is better to either use the mysql cli or phpmyadmin to execute it and make sure it is working before you place it in a script. Quote Link to comment Share on other sites More sharing options...
limitphp Posted November 14, 2008 Author Share Posted November 14, 2008 Why aren't you adding any code to test if the query is even working? $query = "INSERT INTO songcomments (songID, userID, username, comment, date) VALUES ('2', '2', '2', '2', DATE_ADD(NOW())"; mysql_query($query) or die ($query.'<br><br>'.mysql_error()); Good point....the answer is I don't know...but I just added it. It says: 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 ')' at line 2 Line two is my include to the connection to the database code: include("connWebsite.php"); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 14, 2008 Share Posted November 14, 2008 So, the error message tells you to check the mysql manual for the syntax to use near the ')'. That would be the DATE_ADD() portion of your query. Did you check the mysql manual for what the DATE_ADD() syntax should be? Quote Link to comment Share on other sites More sharing options...
limitphp Posted November 14, 2008 Author Share Posted November 14, 2008 So, the error message tells you to check the mysql manual for the syntax to use near the ')'. That would be the DATE_ADD() portion of your query. Did you check the mysql manual for what the DATE_ADD() syntax should be? No, I don't know what the mysql manual is or where it is. Is it a website or something that is installed when you install wamp server? Quote Link to comment Share on other sites More sharing options...
revraz Posted November 14, 2008 Share Posted November 14, 2008 You were missing a ending ) $query = "INSERT INTO songcomments (songID, userID, username, comment, date) VALUES ('2', '2', '2', '2', NOW())"; Quote Link to comment Share on other sites More sharing options...
limitphp Posted November 14, 2008 Author Share Posted November 14, 2008 Ok, I figured it out.... DATE_ADD is used only if you want to add something to the date today. Thus, it was expecting me to add an interval to now date (seconds, minutes, days, etc). All I wanted to do was insert todays date in the date field. I thought you had to have the DATE_ADD to do that. Turns out, you just have to put now(). Learn something everyday..... Thanks. I also figured out that the MYSQL manual is a website. In fact when i tested the mysql in the phpadmin it had a little question mark you could click that took me to it. I never thought to test my sql statements in the phpadmin first. I'm going to start now. I also never understood the importance of adding the error statement to EVERY query, etc. I do now. Thanks.... Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 14, 2008 Share Posted November 14, 2008 It says: 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 ')' at line 2 Line two is my include to the connection to the database code: include("connWebsite.php"); A mysql error does not indicate the line number error in your PHP code -it indicates the error in the mysql query. 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.