Jump to content

query prob


astralaaron

Recommended Posts

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?

Link to comment
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.

Link to comment
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 :)

Link to comment
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.

Link to comment
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!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...