我完全是php和mysql的初学者。我想把(年份,月份,需求)放在数据库中的(表)中,但是var_dump显示Bool(false),没有任何东西被传递给数据库.它还显示成功注册的警报。这是我的完整代码
<html>
<head>
<title>Simulation</title>
</head>
<body>
<h2>Registration Page</h2>
<a href="home.php"> Click here to go back </a><br/><br/>
<form action="register.php" method="POST">
Enter year: <input type="number" name="year" required="required" /> <br/>
Enter month: <input type="number" name="month" required="required" /> <br/>
Enter demand: <input type="number" name="demand" required="required" /> <br/>
<input type="submit" value="Register"/>
</form>
</body>
</html>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$year = mysql_real_escape_string ($_POST['year']);
$month = mysql_real_escape_string ($_POST['month']);
$demand = mysql_real_escape_string ($_POST['demand']);
echo " year is" .$year. "<br/>";
echo " month is" .$month. "<br/>";
echo " demand is" .$demand;
mysql_connect("localhost", "root","") or die(mysql_error()); //Connect to server
mysql_select_db("first_db") or die("Cannot connect to database"); //Connect to database
$qu = mysql_query("INSERT INTO table (year, month, demand) VALUES ('$year','$month','$demand')"); //Inserts the value to table users
var_dump ($qu);
die();
Print '<script>alert("Successfully Registered!");</script>'; // Prompts the user
Print '<script>window.location.assign("register.php");</script>'; // redirects to register.php
}
?>发布于 2015-04-30 02:22:24
table是保留字,您必须更改表名并使用以下查询:
INSERT INTO Table_Name (year, month, demand) VALUES ('$year','$month','$demand')发布于 2015-04-30 02:57:26
将整个表更改为新的命名用户作为表是一个保留字的问题得到了解决。并编写如下的查询
$qu = mysql_query("INSERT INTO users (year, month, demand) VALUES ('$year','$month','$demand')");发布于 2015-04-30 02:21:57
如果$qu返回false,则表示查询有某种错误,无法执行
在这一行
$qu = mysql_query("INSERT INTO table (year, month, demand) VALUES ('$year','$month','$demand')");您必须附加更像这样的字符串:
$qu = mysql_query("INSERT INTO table (year, month, demand) VALUES ('".$year."','".$month."','".$demand."')");https://stackoverflow.com/questions/29957922
复制相似问题