如何使用PHP将整数存储到MySQL数据库?

时间:2015-04-17 07:26:32

标签: php mysql database integer store

我正在做一个报告目的的网站,所以我需要使用php将数据存储到MySQL。一切都很好,但我无法将整数/数字存储到数据库中。我想我的代码有问题。请帮帮我。

html代码:

 <div id = "forms">
   <form enctype="multipart/form-data" form action="add_data.php" method="post" >

  <li> <label for = "Injured_D" > No. of Injured Driver: </label>
  <input "type = "text" name = "Injured_D" id = "Injured_D" />  
  </li>

<div id = "submit"><button type="submit" >Submit</button> </div><br>
</form>

php代码:

// escape variables for security
$injured_D = mysqli_real_escape_string($con, $_POST['injured_D']);
$sql="INSERT INTO abc (injured_D) VALUES ('$injured_D')";

MySQL设置:

输入:int(30)

整理:无

4 个答案:

答案 0 :(得分:2)

你的代码中有拼写错误

<input "type = "text" name = "Injured_D" id = "Injured_D" />  
                              ^^

应该是

<input "type = "text" name = "injured_D" id = "Injured_D" />  
                              ^^

您在POST内传递 Injured_D ,并以名称 hurt_D 获取

答案 1 :(得分:0)

更改

$sql="INSERT INTO abc (injured_D) VALUES ('$injured_D')";

$sql="INSERT INTO abc (injured_D) VALUES ($injured_D)";

答案 2 :(得分:0)

$sql="INSERT INTO abc (injured_D) VALUES ('$injured_D')";

应该是

$sql="INSERT INTO abc (injured_D) VALUES ($injured_D)";

没有''

答案 3 :(得分:0)

更改自:

$injured_D = mysqli_real_escape_string($con, $_POST['injured_D']);

致:

$injured_D = mysqli_real_escape_string($con, $_POST['Injured_D']);