A HTML form has an input field. The user will enter the value in the HTML form and based on the value further steps will be taken.
The input field accepts characters and that is what is being entered . In the HTML form it is defined correctly.
The problem is the value entered is NOT getting stored in the variable in PHP. This is really simple but for some reason I am not able to catch the problem.
Please note this is NOT the actual code that will be deployed. I am taking care of SQL injection in the deployed code. Just need to figure out what is going wrong here.
I have tried displaying the value entered in the form. It just returns NULL. What am I doing wrong here?
<?php
$host = 'localhost';
$dbname = 'dbname';
$username = 'user';
$password = 'password';
$mysqli = new mysqli("localhost", "user", "password", "dbname");
if($mysqli->connect_error)
{
die("$mysqli->connect_errno: $mysqli->connect_error");
}
$field1=$_POST['field1'];
var_dump($field1);
?>
The HTML code:
<!DOCTYPE html>
<html>
<body>
<basefont face = "sans-serif" size = "2" color = "#ff0000">
<form id="queryForm" method="POST" action="/test.php">
<div class="row">
<fieldset class="hm-fieldset">
<legend class="hm-legend">Enter Query Criteria:</legend>
<div class="col">
<span style="font-family:sans-serif">
Field1<br> <input type="text" id="field1" style="height:10px;
width:105px"> </span>
</div>
<button>Submit</button>
</fieldset>
</div>
</form>
</body>
</html>