I'm using an external php file in the "action" field of my HTML form so that the actions mentioned in the php file are undertaken on clicking the Submit button.
For this I've used the isset()
function in the php file.
However, I'm finding that the isset
function is always returning FALSE
, resulting in the execution of the else statement (as seen in the console log).
If I remove the isset()
function (and hence the if-else
statements), then the code is working wonderfully.
Can you please check the problem in my code?
Also I've seen in other posts that I need to use some other argument along with isset()
, for example,
if(isset($_POST['submit']) && !empty($_POST["xyz"]))
is this at all required?
P.S.: I'm still in the initial stage of the page development and hence I request you to please ignore the security concerns of my code, which I acknowledge that it exists. :)
My Sub-codes:
My HTML Form:
<form id="info-form" method="POST" action="form-submit.php">
<label for="Name">What is your Name? </label>
<input required type="text" name="name" placeholder="Enter your full name here." />
<label for="Email">What is your email ID? </label>
<input required type="email" name="email" placeholder="your.name@email.com" />
<label for="mobile">What is your 10-Digit Mobile Number? </label>
<input required type="text" name="mobile" maxlength="10" />
<button name="submit-form" type="submit" class="btn btn-lg btn-success"><i class="fa fa-paper-plane" aria-hidden="true"></i>
Submit
</button>
<button type="reset" class="btn btn-lg btn-warning"><i class="fa fa-undo" aria-hidden="true"></i>
Reset
</button>
</form>
My form-submit.php file:
<?php
if(isset($_POST['submit-form']))
{
require("database-connect.php");
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$sql = "INSERT INTO tbl_details ".
"(name,email_id,mobile_number) ".
"VALUES ".
"('$name','$email','$mobile')";
mysql_select_db('db_info');
$return = mysql_query( $sql, $connect );
if(! $return )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($connect);
}
else
{
echo "Not Set\n";
}
?>