Jump to content

[SOLVED] Need help with insert not working


limitphp

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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....

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.