I am sending data from html file to php but it is not saving all the values are storing empty in data base i think it is not getting values from html i am using following code
<html>
<body><form action="data.php" method="get">
<input type="text" name="$R1" id="R1" value="John"><br>
<input type="text" name="$R2" id="R2" value="thePassword"><br>
<input type="text" name="$R3" id="R3" value="thePassword"><br>
<input type="text" name="$R4" id="R4" value="thePassword"><br>
<input type="text" name="$R5" id="R5" value="thePassword"><br>
<input type="text" name="$R6" id="R6" value="thePassword"><br>
<input type="text" name="$R7" id="R7" value="thePassword"><br>
<input type="text" name="$R8" id="R8" value="thePassword"><br>
<input type="text" name="$R9" id="R9" value="thePassword"><br>
<input type="text" name="$R10" id="R10" value="thePassword"><br>
<input type="text" name="$R11" id="R11" value="thePassword"><br>
<input type="submit">
</form></body>
</html>
PHP Code For adding data into table it inserts only blank records.
<?php
$con =
mysql_connect("surveyipad.db.6420177.hostedresource.com","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("surveyipad", $con);
$device_Id=$_GET['device_Id'];
$R1=$_GET['R1'];
$R2=$_GET['R2'];
$R3=$_GET['R3'];
$R4=$_GET['R4'];
$R5=$_GET['R5'];
$R6=$_GET['R6'];
$R7=$_GET['R7'];
$R8=$_GET['R8'];
$R9=$_GET['R9'];
$R10=$_GET['R10'];
$R11=$_GET['R11'];
echo($R1);
$update_date_time=$_GET['update_date_time'];
$teritory1=$_GET['teritory1'];
$query=("INSERT INTO std (device_Id,R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,update_date_time,teritory1)
VALUES
('$device_Id','$R1','$R2','$R3','$R4','$R5','$R6','$R7','$R8','$R9','$R10','$R11','$update_date_time','$teritory1')");
mysql_query($query,$con);
printf("Records inserted: %d
", mysql_affected_rows());
?>
Change the name in
<input type="text" name="$R1" id="R1" value="John"><br>
to
<input type="text" name="R1" id="R1" value="John"><br>
name="$R1"
to name="R1"
and try
=> Make your query secure from sql injection.
=> Use mysql_real_escape_string
$query=("INSERT INTO std (device_Id,R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,update_date_time,teritory1)
VALUES
('".mysql_real_escape_string($device_Id)."',
'".mysql_real_escape_string($R1)."',
'".mysql_real_escape_string($R2)."',
'".mysql_real_escape_string($R3)."',
'".mysql_real_escape_string($R4)."',
'".mysql_real_escape_string($R5)."',
'".mysql_real_escape_string($R6)."',
'".mysql_real_escape_string($R7)."',
'".mysql_real_escape_string($R8)."',
'".mysql_real_escape_string($R9)."',
'".mysql_real_escape_string($R10)."',
'".mysql_real_escape_string($R11)."',
'".mysql_real_escape_string($update_date_time)."',
'".mysql_real_escape_string($teritory1)."')");
=> mysql_* functions are deprected, use mysqli_* functions OR PDO
=> NOT IMPORTANT : It is better change method="get"
to method="POST"
, if you do not have specific reason for use get
The name
attributes in your form should not start with $
:
<input type="text" name="R1" id="R1" value="John">
...and so on
Your code is highly vulnerable to Injection. You should update it to stop using ext/mysql
and use properly parameterized statements via PDO
/mysqli
.
You are not sending update_date_time
or territory1
along with the rest of the form either. Any reason to use GET over POST? You should use POST for non-idempotent requests.
Remove $
from name
attribute in your HTML. Change to name="R1"