I have a sign up form in html, but it's not submitting any data to the php file. Weird thing is, to me an exactly the same looking form on the same page does work and this one used to work. I probably somewhere changed something accidently.
The form:
<form action="http://test.com/register.php" method="POST" enctype="multipart/form-data">
<fieldset>
<div align="left">
<label>Username</label>
<input type="text" required class="span11" name="fUsername" id="Username" placeholder="username">
<label>Password</label>
<input type="password" required class="span11" name="fPassword" id="Password" placeholder="password">
<label>Retype password</label>
<input type="password" required class="span11" name="fRetypepassword" id="Retypepassword" placeholder="retype password">
<label>Phone number</label>
<input type="text" required class="span11" name="fPhone" id="Phone" placeholder="+... international format">
<label>E-Mail</label>
<input type="email" required class="span11" name="fEmail" id="Email" placeholder="e-mail">
<br><br>
<button type="submit" class="btn btn-info">Register</button>
</div>
</fieldset>
</form>
The PHP:
$username = htmlspecialchars($_GET['fUsername']);
$password=htmlspecialchars($_GET['fPassword']);
$passwordmatch=htmlspecialchars($_GET['fRetypepassword']);
$email=htmlspecialchars($_GET['fEmail']);
$phone=htmlspecialchars($_GET['fPhone']);
echo $username;
The form is sending data with method POST but you are trying to read it from $_GET.
Try:-
$username = htmlspecialchars($_POST['fUsername']);
$password = htmlspecialchars($_POST['fPassword']);
$passwordmatch = htmlspecialchars($_POST['fRetypepassword']);
$email = htmlspecialchars($_POST['fEmail']);
$phone = htmlspecialchars($_POST['fPhone']);
Related
I would like to work on registration process for which with the help of Google and Youtube i have created "Sign-in & Sing-up" page togather with toggle option however unable to run registration.php file once user provide registration info at login.html file. Codes are as follows :
<form id="login" class="input-group">
<input type="text" class="input-field" placeholder="User Id" required>
<input type="password" class="input-field" placeholder="Enter Password" required>
<input type="checkbox" class="check-box"><span>Remember Password</span>
<button type="submit" class="submit-btn">Sign-In</button>
</form>
<form Id="register" class="input-group">
<input type="text" class="input-field" placeholder="User Id" required>
<input type="email" class="input-field" placeholder="Email Id" required>
<input type="password" class="input-field" placeholder="Enter Password" required>
<input type="password" class="input-field" placeholder="Confirm Password" required>
<input type="phone-number" class="input-field" placeholder="Mobile Number" required>
<input type="checkbox" class="check-box"><span>I agree to the terms & conditions</span>
<button type="submit" class="submit-btn">Sign-Up</button>
</form>
How to execute registration.php file when Sign-up button clicked at login.html file? Same goes for login option too.
Make sure to add method="POST" and action="path/function.php" and name="desiredName"in your forms like this:
<form id="login" class="input-group" method="POST" action="file_path/login.php">
<input type="text" class="input-field" placeholder="User Id" name ="user" required>
<input type="password" class="input-field" placeholder="Enter Password" name="password" required>
<input type="checkbox" class="check-box"><span>Remember Password</span>
<button type="submit" class="submit-btn">Sign-In</button>
</form>
And then in PHP to "catch" the data from the post, you'll use something like this:
$this->getpost['user'];
Or
$_POST['user'];
The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute).
The form-data can be sent as URL variables (with method="get") or as HTTP post transaction (with method="post").
check here for more details w3schools
<form id="login" class="input-group" method="POST" action="file_path/login.php">
<input type="text" class="input-field" placeholder="User Id" required>
<input type="password" class="input-field" placeholder="Enter Password" required>
<input type="checkbox" class="check-box"><span>Remember Password</span>
<input type="submit" class="submit-btn" value="Sign-In">
</form>
<form Id="register" class="input-group" method="POST" action="file_path/register.php">
<input type="text" class="input-field" placeholder="User Id" required>
<input type="email" class="input-field" placeholder="Email Id" required>
<input type="password" class="input-field" placeholder="Enter Password" required>
<input type="password" class="input-field" placeholder="Confirm Password" required>
<input type="phone-number" class="input-field" placeholder="Mobile Number" required>
<input type="checkbox" class="check-box"><span>I agree to the terms & conditions</span>
<input type="submit" class="submit-btn" value="Sign-Up">
</form>
EDIT according to your comment
replace button with input type="submit"
and place # before the php variable so you wont get undefined error notice(# is used to avoid error notice)
<div class="header">
<h2>Register here</h2>
</div>
<form method="post" action="register.php">
<?php include('errors.php'); ?>
<div class="input-group">
<label>Username</label>
<input type="text" name="username" value="<?php echo #$username; ?>">
</div>
<div class="input-group">
<label>Email</label>
<input type="email" name="email" value="<?php echo #$email; ?>">
</div>
<div class="input-group">
<label>Password</label>
<input type="password" name="password_1">
</div>
<div class="input-group">
<label>Confirm Password</label>
<input type="password" name="password_2">
</div>
<div class="input-group">
<label>Mobile number</label>
<input type="number" name="mobile" value="<?php echo #$mobile; ?>">
</div>
<div class="input-group">
<input type="submit" class="btn" name="reg_user" value="Sign-Up">
</div>
</form>
create register.php file
and in register.php
<?php
$con = mysqli_connect("localhost", "username", "password", "dbname") or trigger_error("Unable to connect to the database");
if(isset($_POST['reg_user'])){
$name = $_POST['username']; //here "username" is what you defined in the "name" field of input form
//define other variables
//write your own sql query , here is an example
$query = "INSERT INTO table(name) VALUES(?)";
$stmt = mysqli_stmt_init($con);
if(!mysqli_stmt_prepare($stmt,$query)){
echo "Error";
}else{
mysqli_stmt_bind_param($stmt,"s",$name);
mysqli_stmt_execute($stmt);
}
}
?>
I'm designing a login webpage and it looks like this:
where the '123456' is the password.
However, when I tried to hide the password by changing my code as:
<input Name="Password" type="password" id="Password" placeholder="Password" required="">
the input box for password became this:
So are there any ways to hide the password but keep the format of inputting text box?
Here's my source code:
<form action="login_singletest.php" method="post">
<div class="w3_cc">
</div>
<input type="text" class="margin-right" Name="Email" placeholder="Email" required="">
<input Name="Password" type="text" id="Password" placeholder="Password" required="">
<div class="clearfix"></div>
<div class="send-button agileits w3layouts">
<button class="btn btn-primary">Log In </button>
</div>
</form>
<input type="email" class="margin-right" Name="Email" placeholder="Email" required>
<input type="password" class="margin-right" type="password" name="Password" placeholder="Password" required>
My apology. My classmate passed me the wrong css file in which she didn't define "type = password". Now everything's settled after the css file was modified. #FunkFortyNiner Thank you very much for being so patient.
We were doing a project which involved a website and a database. We decided to host it using 000webhost.
So, we have 2 different forms, and both should redirect to different PHPs, but both end up redirecting to the same php.
I have attached the code of the forms here:
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<form action="csignup.php">
<div class="container">
<label><b>NAME<b></label><br>
<input type="text" placeholder="Enter Fullname" name="fname" required>
<br><label><b>email</b></label><br>
<input type="text" placeholder="Enter email" name="email" required><br>
<br><label><b>USERNAME</b></label><br>
<input type="text" placeholder="Enter username" name="uname" required><br>
<br><label><b>password</b></label><br>
<input type="password" placeholder="Enter password" name="pass" required><br>
<br><label><b>Re-password</b></label><br>
<input type="password" placeholder="Enter password" name="rpass" required><br>
<button type="SUBMIT">SUBMIT</button>
</div>
</form>
</div>
</div>
<!-- Modal content -->
<div class="modal1-content">
<span class="close1">×</span>
<form action="asignup.php">
<div class="container">
<label><b>NAME<b></label><br>
<input type="text" placeholder="Enter Fullname" name="fname" required>
<br><label><b>email</b></label><br>
<input type="text" placeholder="Enter email" name="email" required><br>
<br><label><b>USERNAME</b></label><br>
<input type="text" placeholder="Enter username" name="uname" required><br>
<br><label><b>password</b></label><br>
<input type="password" placeholder="Enter password" name="pass" required><br>
<br><label><b>Re-password</b></label><br>
<input type="password" placeholder="Enter password" name="rpass" required><br>
<button type="SUBMIT">SUBMIT</button>
</div>
</form>
</div>
</div>
We have mainly 2 PHPs for the signup option. "asignup.php" and "csignup.php".
But on clicking submit, on either of the forms, redirects and uses the "asignup.php".
We are not able to redirect to "csignup.php", even though we have specified it as the form action for one of the forms. Please take a look through it, and help us out.
Thanks
I have been trying to figure out why Chrome auto fills the wrong fields. Every tutorial I have seen says to shut off but that is not a good idea since my users would have to turn off their auto-fill and that is just no a solution. Here is the code I am using.
<form class="form" action="login.php" method="post" enctype="multipart/form-data" autocomplete="off">
<div style="margin-top: 60px;margin-bottom: 20px;color: #b30000;" class="alert alert-error"></div>
<center>
<?php echo($_SESSION['loginerror']);?>
<input style="margin-top: -40px;" type="text" placeholder="Email Address" name="email" required />
<br>
<input style="margin-top: 0px;" type="password" placeholder="Password" name="password" required>
<br>
<input type="submit" value="Log-In" name="submit" style="width: 50%;margin-left: 20px;margin-top: 15px;" class="btn btn-block btn-primary" />
<p style="margin-top: 10px;font-size: 12px;">Forgot your password? Click Here</p>
</center>
<br>
Here is a screen shot of how it appears to the user. It is my street address.
You can use type="email" to give the browser a hint.
<input type="email" name="email">
<input type="password" name="password">
Add autofill attribute to input, will solve this issue
<input ..... autocomplete="off">
P.N: As i know Firefox will not respond to this
check browser compatibility
You can change it to the following
<input ... type="text" name="email" required>
<input ... type="password" name="password" autocomplete="new-password">
or
<input ... type="email" name="email" required>
<input ... type="password" name="password" autocomplete="new-password">
I am having difficulty understanding why my application is sending an empty POST array upon form submission in my PHP MVC app.
I have the following code in my Register/Index view:
<form class="form-register" action="/register/checkregister" method="post">
<img src="/img/logo.png" class="logo">
<label for="name" class="sr-only">Name</label>
<input type="text" id="name" class="form-control" placeholder="Name" required autofocus>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<label for="retypePassword" class="sr-only">Re-Type Password</label>
<input type="password" id="retypePassword" class="form-control" placeholder="Re-type Password" required>
<br>
<button class="btn btn-lg btn-success btn-block" type="submit">Register</button><br>
Back to Login Page
</form>
I was expecting this to give me access to the $_Post array from within my register/checkRegister method. However when I check the $_Post variable it shows that it has been submitted but with no values.
I am new to development in this way, if anyone could help with what I am doing wrong that would be great.
I tried to check within my checkRegister method in the Register controller by using this code:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
echo "<pre>";
var_dump($_POST);
echo "</pre>";
$user_name = Request::post('name');
echo 'user_name = '.$user_name . '<br><br>';
echo "POST";
}
But it returns an empty array for Post.
My code is on GitHub:
https://github.com/imoprojects/upbook
Thank you for any assistance,
Ian
you have not added the name attribute to your input tags
add name attribute to every input tag like this
<form class="form-register" action="/register/checkregister" method="post">
<img src="/img/logo.png" class="logo">
<label for="name" class="sr-only">Name</label>
<input type="text" name="name" id="name" class="form-control" placeholder="Name" required autofocus>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" name="inputEmail" id="inputEmail" class="form-control" placeholder="Email address" required>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="inputPassword" id="inputPassword" class="form-control" placeholder="Password" required>
<label for="retypePassword" class="sr-only">Re-Type Password</label>
<input type="password" name="retypePassword" id="retypePassword" class="form-control" placeholder="Re-type Password" required>
<br>
<button class="btn btn-lg btn-success btn-block" type="submit">Register</button><br>
Back to Login Page
</form>