Jump to content
Sign in to follow this  
astralaaron

query prob

Recommended Posts

just trying to use the NOW() in my sql query$query = "INSERT INTO `post` (`name`, `time`)VALUES('$name', NOW());";$result = mysql_query($query);can someone tell me what im doing wrong here because it wont execute the query

Share this post


Link to post
Share on other sites

problem 1:$query = "INSERT INTO `post` (`name`, `time`)VALUES('$name', NOW());"; //take out the all of the " ' " in there... other wise, it is searching for a table named 'post'problem 2:what is the function NOW()? if it is not returning any thing, then it won't work. try saying RETURN "a value";problem 3:try saying:$result = mysql_query("INSERT INTO `post` (`name`, `time`)VALUES('$name', NOW())");do you really need the $query var?

Share this post


Link to post
Share on other sites

The original code should work, the backquotes are fine, the syntax for the NOW function is fine, and a variable isn't going to cause the query to fail.But it would help to know what the error message is. Is there a non-escaped quote in the $name variable? Try adding spaces around VALUES, I don't know if that is required or not.

Share this post


Link to post
Share on other sites

I have the same problem with my db so I used this instead:

$query = "INSERT INTO post ('name', 'time') VALUES ('$name', NOW());";$result = mysql_query($query);

Oh! and space around VALUES will help too :)

Share this post


Link to post
Share on other sites

The single quotes around name and time are going to cause problems, you either need to use backquotes like in the original code or no quotes. If you use single or double quotes then you're saying it's a string, but it needs to be an identifier for a column.

Share this post


Link to post
Share on other sites
just trying to use the NOW() in my sql query$query = "INSERT INTO `post` (`name`, `time`)VALUES('$name', NOW());";$result = mysql_query($query);can someone tell me what im doing wrong here because it wont execute the query
Try this
$Rsql = mysql_query("INSERT INTO post (name, time) VALUES ('$name',NOW())") or die (mysql_errno() .": ". mysql_error());

and tell us the message you got!

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...