頁面有個提交表單,如下:<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來傳遞嗎?謝謝各位!

解决方案 »

  1.   

    '$_POST[age]'去掉'  改成$_POST[age]   你都int  还加'怎么可能行呢
      

  2.   

    把 ‘ 去掉了,但是還報錯。報錯信息是:Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 3
      

  3.   

    恩,確實是。
    我把引用頁面給添加錯了,導致直接跳轉到 insert.php頁面了,所以報錯了謝謝大家!