MySQL Insert Into table
mysql_query("INSERT INTO contact_forms(name,ts,ip,email,option,msg)
VALUES('".$name."',
NOW(),
'".$_SERVER['REMOTE_ADDR']."',
'".$email."',
'".$option."',
'".开发者_StackOverflow社区$message."')");
For some reason this thing doesn't work. It throws no errors but it just doesn't work. Can someone tell me why?
Assuming you are doing this in PHP, which is what it appears to be, try changing your code to this to see if you get an error that might be able to add a little more information:
mysql_query("INSERT INTO contact_forms(name,ts,ip,email,option,msg)
VALUES('".$name."',
NOW(),
'".$_SERVER['REMOTE_ADDR']."',
'".$email."',
'".$option."',
'".$message."')", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "<br>";
In this example the variable $link
is your database connection string.
See http://php.net/manual/en/function.mysql-error.php for more information on usage.
Put mysql_error() as zerkms suggested.
Update
option is a MySQL [link=http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html]reserved word[/link] and you can not use it unless you enclose it with back tick (`).
mysql_query("INSERT INTO contact_forms(name,ts,ip,email,`option`,msg)
VALUES('".$name."',
NOW(),
'".$_SERVER['REMOTE_ADDR']."',
'".$email."',
'".$option."',
'".$message."')");
Always use mysql_error() to debug query issues. It is not a good practice to use reserve words in database schema.
Try
$date = now(); $ip = $_SERVER['REMOTE_ADDR']; $query = "INSERT INTO contact_forms (name,ts,ip,email,option,msg) VALUES('$name', '$date', '$ip', '$email', '$option', '$message')";
精彩评论