user3934569
user3934569

Reputation: 49

How to store integer numbers to MySQL database using php?

I am doing a website for some reporting purpose, so I need to store data to MySQL using php. everything is good but I can't store integers/numbers to the database. I guess there's something wrong with my code. Please help me out.

html code:

 <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 code:

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

MySQL Settings:

Type: int(30)

Collation: none

Upvotes: 0

Views: 2856

Answers (4)

Amrita Gupta
Amrita Gupta

Reputation: 37

Change from :

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

To :

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

Upvotes: 0

Narendrasingh Sisodia
Narendrasingh Sisodia

Reputation: 21437

You had typo within your code

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

It should be

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

You were passing Injured_D within POST and getting it with name injured_D

Upvotes: 2

Sudip Gautam
Sudip Gautam

Reputation: 46

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

should be

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

without ' '

Upvotes: 0

Arun
Arun

Reputation: 3721

Change

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

to

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

Upvotes: 0

Related Questions