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

How to store integer numbers to MySQL database using php?

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

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 设置:

类型:整数(30)

整理:none

改变

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

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

应该是

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

没有' '

您的代码中有拼写错误

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

应该是

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

您在 POST 内传递 Injured_D 并使用名称 injured_D

更改自:

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

收件人:

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