Reputation: 3
I'm trying to print values submitted in the form using post method. But i cant get to display anything. After submitting the form anything is displayed. Not even the sentence in echo. I am unable to figure out what is wrong with my code. thanks in advance.
I have tried using if($_SERVER["REQUEST_METHOD"]=="POST"){}
, I have tried to put the variable in isset()
, still did not work.
register.php
<?php
session_start();
include('config.php'); // this is database connection file
error_reporting(0);
echo $_POST["name"];
?>
config.php
<?php
$con = mysqli_connect("localhost","root","","music_pro");
if(mysqli_connect_errno()){
echo"Failed to connect : " . mysqli_connect_error();
}
?>
html code
<form method="post" name="register" action="register.php">
<label for="name"><b>Name</b></label>
<input type="text" name="name" placeholder="Enter your name" required>
<label for="email"><b>Email</b></label>
<input type="text" name="email" placeholder="Enter your email id"
required>
<label for="uname"><b>User ID</b></label>
<input type="text" name="uname" placeholder="Enter your user id"
required>
<label for="password"><b>Password</b></label>
<input type="password" name="password" placeholder="Enter your
password"
id="pwd" required>
<label for="confirmPassword"><b>Confirm Password</b></label>
<input type="password" name="confirmpassword" placeholder="Please
confirm password" id="cofirmpsw" required>
<input type="submit" value="Register"></form>
Upvotes: 0
Views: 98
Reputation: 175
if your form and php code are in one page then change first line of form as below:
<form method="post" name="register" action="<?php echo $_SERVER['SCRIPT_NAME''];?>">
Upvotes: 0
Reputation: 18557
I think you are missing something, check if $_POST
empty or not,
register.php
<?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
session_start();
include 'config.php'; // this is database connection file
if (!empty($_POST)) {
echo "<pre>";
print_r($_POST);die;
}
?>
config.php
<?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$con = mysqli_connect("localhost", "root", "", "music_pro");
if (mysqli_connect_errno()) {
echo "Failed to connect : " . mysqli_connect_error();
}
?>
yourxyz.html or yourxyz.php
<form method="post" name="register" action="register.php">
<label for="name"><b>Name</b></label>
<input type="text" name="name" placeholder="Enter your name" required>
<label for="email"><b>Email</b></label>
<input type="text" name="email" placeholder="Enter your email id" required>
<label for="uname"><b>User ID</b></label>
<input type="text" name="uname" placeholder="Enter your user id" required>
<label for="password"><b>Password</b></label>
<input type="password" name="password" placeholder="Enter your
password" id="pwd" required>
<label for="confirmPassword"><b>Confirm Password</b></label>
<input type="password" name="confirmpassword" placeholder="Please
confirm password" id="cofirmpsw" required>
<input type="submit" value="Register">
</form>
This should work. And once check whether input element is having a name attribute with name as its name.
Upvotes: 1