我的register.php不会查询最简单的查询:
<?php
session_start();
/* Connect and Query database "accounts", then close connection */
$connection=mysql_connect("localhost","root","");
if (!$connection)
{
die('Cannot connect to MySQL. Error: ' . mysql_error());
}
$check_database = mysql_select_db("accounts", $connection);
if (!$check_database)
{
die('Cannot connect to database. Error: ' . mysql_error());
}
/* Query database to save user's post */
/* If field "repostid=0", then the post is not a repost; if the field "repostid>0", then the post is a repost with the field linking to the id of the post to be reposted */
$result = mysql_query("INSERT INTO posts2 (from) VALUES ('h1')");
if (!$result)
{
die('Cannot query. Error: ' . mysql_error());
}
/* Close Connection */
mysql_close($connection);
/* Redirect to user's page */
header("Location: /website/index.php", 404);
exit();
?>
Run Code Online (Sandbox Code Playgroud)
这是echo'd错误消息:
无法查询.错误:SQL语法中有错误; 查看与您的MySQL服务器版本对应的手册,以便在第1行的'from)VALUES('h1')附近使用正确的语法
它从post.php上的表单调用:
<form name="postForm" action="userpost.php" method="post" enctype="multipart/form-data" onsubmit="validatePostForm()">
<div id="posttext"><p>Enter the text you wish to post, then press "Post":</p></div>
<div id="posttextarea"><textarea rows="10" cols="80" name="postinfo" onkeydown="characterTyping('postbuttoncharactersleft')"></textarea></div>
<div id="postbutton"><input type="submit" value="Post"/></div><p id="postbuttoncharactersleft">250</p><p id="postbuttoncharacterslefttext"> characters left.</p>
</form>
Run Code Online (Sandbox Code Playgroud)
这是数据库表,因此您可以确认它是对此表的查询的正确语法:

你需要像使用反引号一样逃避MySQL中的保留字from
INSERT INTO posts2 (`from`) VALUES ('h1')
Run Code Online (Sandbox Code Playgroud)