頁面有個提交表單,如下:<html>
<body>
<form action="insert.php" method="post">
name: <input type="text" name="name" />
telephone: <input type="text" name="telephone" />
age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
<?php
$con = mysql_connect("localhost","root","321232");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("mysql", $con);$sql="INSERT INTO friends (name, telephone, age)
VALUES
('$_POST[name]','$_POST[telephone]','$_POST[age]')";if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>爲什麽報錯啊,請教各位,像這種age為int型的不能通過text來傳遞嗎?謝謝各位!
<body>
<form action="insert.php" method="post">
name: <input type="text" name="name" />
telephone: <input type="text" name="telephone" />
age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
<?php
$con = mysql_connect("localhost","root","321232");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("mysql", $con);$sql="INSERT INTO friends (name, telephone, age)
VALUES
('$_POST[name]','$_POST[telephone]','$_POST[age]')";if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>爲什麽報錯啊,請教各位,像這種age為int型的不能通過text來傳遞嗎?謝謝各位!
我把引用頁面給添加錯了,導致直接跳轉到 insert.php頁面了,所以報錯了謝謝大家!