Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have an HTML form with three inputs: Make, Year, Mileage.
The conditions are that Make should not be empty, and Year and Mileage must be numeric.
The form submits when the conditions are met.
However, when one of the conditions is not met, I'm using PHP to redirect to the same page and display an error message on the screen. Now when I enter correct values, the form wouldn't submit. Nor does the cancel button redirects it to the previous page.
If I want the form to submit after the error message has been displayed, I have to refresh it and then enter correct values. How can I avoid the refresh?
Here's the code:
<?php
session_start();
require_once "pdo.php";
if (!isset($_SESSION['email']) || strlen($_SESSION['email']) < 1) {
die('Not logged in');
}
if (isset($_POST['cancel'])) {
header("Location: view.php");
return;
}
if (isset($_POST['make']) && isset($_POST['year']) && isset($_POST['mileage'])) {
if (strlen($_POST['make']) < 1) {
$_SESSION['failure'] = "Make is required";
header("Location: add.php");
return;
}
else {
if (!is_numeric($_POST['year']) || !is_numeric($_POST['mileage'])) {
$_SESSION['failure'] = "Mileage and year must be numeric";
header("Location: add.php");
return;
}
else {
$sql = "INSERT INTO autos(make, year, mileage)
VALUES(:mk, :yr, :ml)";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
':mk' => $_POST['make'],
':yr' => $_POST['year'],
':ml' => $_POST['mileage']
));
$_SESSION["record"] = "Record inserted";
header("Location: view.php");
return;
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mohammed Misran's Automobile Tracker</title>
</head>
<body>
<h1>Tracking Autos for <?php echo htmlentities($_SESSION['email']);?></h1>
<?php
if (isset($_SESSION['failure'])) {
echo '<p style="color: red;">'.htmlentities($_SESSION['failure'])."</p\n";
unset($_SESSION['failure']);
}
?>
<form method="post">
<p>Make:
<input type="text" name="make" size="40"/></p>
<p>Year:
<input type="text" name="year" size="40"/></p>
<p>Mileage:
<input type="text" name="mileage" size="40"/></p>
<p><input type="submit" value="Add"/>
<input type="submit" name="cancel" value="Cancel"/></p>
</form>
</body>
</html>
Good Afternoon,
I think its better to use HTML form properties, you want to validate the entered values, so its easy to do it like this:
1- 'Make' should not be empty:
<input type="text" name="make" size="40" required/>
2- 'Year' and 'Mileage' must be numeric:
<input type="number" name="year" size="40"/>
<input type="number" name="mileage" size="40"/>
by this way you dont need to write any php validation for your form, if you want to use php validation let me know to guide you for solving your problem
when Submit button press then first you have to Check Submit Button Post like this:
if(isset($_POST['submit'])){
//Your Code Logic...
}
then get data from POST & store it in variable like this... for Your Reference
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
}
in html...
<body>
<form method="post" action="">
<input type="text" name="username" placeholder="enter username"><br/><br/>
<input type="text" name="password" placeholder="enter password"><br/><br/>
<input type="submit" name="submit" value="submit"/>
</form>
then store in database like this
$sql="insert into user(username, password)
values('$username','$password')";
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to do a simple thing, create a login page that shows successful login and logoff messages, but it always shows the successful login message ("Logado com sucesso"). My hosting is Hostinger. Here is my code:
<?php
require_once('db.php');
session_start();
if(isset($_POST['action'])){
if($_POST['action'] = 'login'){
$_SESSION['login'] = $_POST['login'];
$msg = 'Logado com sucesso!';
} elseif($_POST['action'] = 'logoff') {
$msg = 'Deslogado com sucesso!';
unset($_SESSION['login']);
}
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<div id="container">
<form method="POST">
<? if(!$_SESSION['login']){ ?>
<h3>Preencha os seus dados abaixo</h3>
<input type="hidden" name="action" value="login">
<input type="text" required name="login" placeholder="Nome de usuário">
<input type="password" required name="senha" placeholder="Senha">
<input type="submit" value="Entrar">
<? } else { ?>
<h3>Você está logado como</h3>
<input type="hidden" name="action" value="logoff">
<input type="text" required name="login" disabled value="<?=$_SESSION['login']?>">
<input type="submit" value="Sair">
<? } ?>
<? if(isset($msg)){ ?>
<div id="msg"><? echo $msg?></div>
<?} ?>
</form>
</div>
</body>
</html>
Your if statements are performing assignment and not a comparison.
For example
if($_POST['action'] = 'login')
is assigning $_POST['action'] = 'login' and will always be TRUE.
You need == so that would become
if($_POST['action'] == 'login')
I am new to PHP and am trying to do Server Side Form Validation. There are two PHP files Login.php and Form.php. Registration is done in Login.php and Validation in Form.php. The idea is that Form.php will process the form data sent by Login.php
My problem: even if form fields are empty, the variables are still being inserted into the database.
I don't want to insert if its empty. Rather, it has to route back to Login.php with error messages stored as a session variable.
I have checked the Form fields using !isset() and empty in Form.php using an if..else clause. In the if..else clause you can find out if the form fields are empty, and if so, they must go the session variable clause (inside the if condition). Instead, it is going to the else condition and inserting the empty values in variables ('$username','$password','$phone','$mailid','$city') in to the database.
I have read previous questions for similar problem here and even checked Youtube for Server Side Validation. What did I do wrong? Is there a problem with the use of session variables. Kindly assist
Login.php:
<!Doctype HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href= "Form.css" />
<script src="Form.js" type="text/javascript"></script>
</head>
<body>
<?php
session_start();
$passworderr='';
if(isset($_SESSION["passworderr"])) {
$passworderr=$_SESSION["passworderr"];
}
?>
<div id="Outer">
<div id="left" >
<form action="/DatabaseDrivenWebpage/Form.php" method="POST" name="form">
<p><label>Username</label> <input type="text" name="regusername" placeholder="Your name"/> </p>
<p><label>Password</label> <input type="text" name="regpassword" placeholder="Password"/> </p>
<input type="Submit" value="Login" />
</form>
</div>
<div id="right">
<form action="/DatabaseDrivenWebpage/Form.php" method="POST" id="formm">
<p>*Username <input required name="username" type="text" /><?php //echo $usernameerr;?></p>
<p>*Password <input name="password" type="password" /> <?php echo $passworderr;?></p>
<p> *Phone <input name="phone" type="tel" /><?php //echo $phoneerr;?></p>
<p> *MailId <input name="mailid" type="email" /><?php //echo $mailiderr;?></p>
<p> *City <input name="city" type="text" /><?php //echo $cityerr;?></p>
<input type="Submit" value="Signup" />
</form></div></div></body></html>
Form.php:
<?php
session_start();
$dbservername='localhost';$dbname='mani';$dbusername='root';$dbpassword='';
$dbconn=mysqli_connect($dbservername,$dbusername,$dbpassword);
if(!$dbconn){
die("Connection failed:". mysqli_connect_error());
}
if(!isset($_POST["username"])) {
$_SESSION["usernameerr"]="UserName is required";
}
else{
$username=mysqli_real_escape_string($dbconn,$_POST["username"]);
}
if(!isset($_POST["password"])) {
$_SESSION["passworderr"]="Enter a password";
}
else{
$password=mysqli_real_escape_string($dbconn,$_POST["password"]);
}
if(!isset($_POST["phone"])) {
$_SESSION["phoneerr"]="Phone number is required";
}
else{
$phone=mysqli_real_escape_string($dbconn,$_POST["phone"]);
}
if(!isset($_POST["mailid"])) {
$_SESSION["mailiderr"]="Enter a valid mail id";
}
else{
$mailid=mysqli_real_escape_string($dbconn,$_POST["mailid"]);
}
if(!isset($_POST["city"])) {
$_SESSION["cityerr"]="Enter your resident city";
}
else{
$city=mysqli_real_escape_string($dbconn,$_POST["city"]);
}
$selected = mysqli_select_db($dbconn,"$dbname")
or die("Could not select examples".mysqli_error($dbconn));
if(isset($_POST["username"]) and isset($_POST["password"]) and isset($_POST["phone"]) and isset($_POST["mailid"]) and isset($_POST["city"]) )
{
$res=mysqli_query($dbconn,"Insert into user(username,password,phone,mailid,city) values('$username','$password','$phone','$mailid','$city')");
if($res)
{
header("location:Login.php");
}
}
else
{
print "Problem in inserting";
header("location:Login.php");
}
mysqli_close($dbconn);
?>
There are a bunch of ways to do this. A blank form field is present on the server side with an empty value. So in addition to checking if the variable is set, in your case you want to check if the value is non-empty.
One way to do that is to use the strlen function.
So an example for you is:
if(!isset($_POST["username"]) || strlen($_POST["username"]) == 0) {
NOTE: Do not use the empty function since the string "0" is considered 'empty'. Read the manual for other such cases.
You may want to consider using a helper function to do the determination. Basically something like this:
function DoesPostFormFieldHaveValue($formFieldName) {
return(
isset($_POST[$formFieldName])
&& strlen($_POST[$formFieldName]) > 0
);
}
First of all, session_start should always be the first line of the php page you need to use sessions on.
Also, I'm not sure why you are using so many session variables for storing errors. Instead of this, use a single session variable, declare it as array and store all the errors in it.
Here's your updated form :-
<?php
session_start();
if((isset($_SESSION['errors']))) //check if we have errors set by the form.php page
{
echo "Please fix the following errors";
foreach($_SESSION['errors'] as $error) //loop through the array
{
echo $error;
}
}
?>
<!Doctype HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href= "Form.css" />
<script src="Form.js" type="text/javascript"></script>
</head>
<body>
<div id="Outer">
<div id="left" >
<form action="/DatabaseDrivenWebpage/Form.php" method="POST" name="form">
<p><label>Username</label> <input type="text" name="regusername" placeholder="Your name"/> </p>
<p><label>Password</label> <input type="text" name="regpassword" placeholder="Password"/> </p>
<input type="Submit" value="Login" />
</form>
</div>
<div id="right">
<form action="/DatabaseDrivenWebpage/Form.php" method="POST" id="formm">
<p>*Username <input required name="username" type="text" /><?php //echo $usernameerr;?></p>
<p>*Password <input name="password" type="password" /> <?php echo $passworderr;?></p>
<p> *Phone <input name="phone" type="tel" /><?php //echo $phoneerr;?></p>
<p> *MailId <input name="mailid" type="email" /><?php //echo $mailiderr;?></p>
<p> *City <input name="city" type="text" /><?php //echo $cityerr;?></p>
<input type="Submit" value="Signup" />
</form></div></div></body></html>
Backend processing file :-
<?php
session_start();
$_SESSION['errors'] = array(); //declare an array
$dbservername='localhost';$dbname='mani';$dbusername='root';$dbpassword='';
$dbconn=mysqli_connect($dbservername,$dbusername,$dbpassword);
if(!$dbconn){
die("Connection failed:". mysqli_connect_error());
}
if((!isset($_POST["username"])) || (empty($_POST['username']))) {
$_SESSION["errors"][]="UserName is required"; //push error message to array if $_POST['username'] is empty or is not set
}
else{
$username=mysqli_real_escape_string($dbconn,$_POST["username"]);
}
if((!isset($_POST["password"])) || (empty($_POST['password']))) {
$_SESSION["errors"][]="Enter a password";
}
else{
$password=mysqli_real_escape_string($dbconn,$_POST["password"]);
}
if((!isset($_POST["phone"])) || (empty($_POST['phone']))) {
$_SESSION["errors"][]="Phone number is required";
}
else{
$phone=mysqli_real_escape_string($dbconn,$_POST["phone"]);
}
if((!isset($_POST["mailid"])) || (empty($_POST['mailid']))) {
$_SESSION["errors"][]="Enter a valid mail id";
}
else{
$mailid=mysqli_real_escape_string($dbconn,$_POST["mailid"]);
}
if((!isset($_POST["city"])) || (empty($_POST['city']))) {
$_SESSION["errors"][]="Enter your resident city";
}
else{
$city=mysqli_real_escape_string($dbconn,$_POST["city"]);
}
$selected = mysqli_select_db($dbconn,"$dbname")
or die("Could not select examples".mysqli_error($dbconn));
if(count($_SESSION['errors']) < 1) //check if the the $_SESSION['errors'] count is less than 1 (0), this means there are no errors.
{
$res=mysqli_query($dbconn,"Insert into user(username,password,phone,mailid,city) values('$username','$password','$phone','$mailid','$city')");
if($res)
{
header("location:Login.php");
}
}
else
{
print "Problem in inserting";
header("location:Login.php");
}
mysqli_close($dbconn);
?>
The thing about isset is that it checks if the variable exists, and therefore allows variables that contain an empty string, like you have. When the current form is submitted without any user input, it is submitting a whole bunch of variables containing empty strings.
Now the solution is to change all your isset() to empty() and that should solve your problem!
[Note] There is no need to use both isset() and empty() like this:
if(!isset($_POST['fieldname']) && !empty($_POST['fieldname']))
because empty() is doing everything that isset() does.
check like this:
if(!isset($_POST["username"]) && $_POST["username"]!="")
Your PHP code is checking for isset only, I don't see any empty check. isset will be always true in your case to either of the forms, as the form fields are submitting - just the values are blank.
To prevent empty insertions, add a !empty check to your conditions. Your conditional statements should look like this -
if(!isset($_POST['fieldname']) && !empty($_POST['fieldname']))
first of all a little advice. If you want to start a new project, I would advice you learn how to use PDO connection to MySQL Databases, and not MySQLi. As PDO is much better method, and secured (especially when using prepared statements).
Anyway, as I can see you are storing the errors in a multiple $_SESISON variables, but after you are finishing the validation checks, you are not doing a correct if statement.
Instead of doing that:
if(isset($_POST["username"]) and isset($_POST["password"]) and isset($_POST["phone"]) and isset($_POST["mailid"]) and isset($_POST["city"]) )
Do something like this:
if(!isset($_SESSION['usernameerr']) && !isset($_SESSION['passworderr']) && !isset($_SESSION['phoneerr'] && !isset($_SESSION['mailiderr'] && !isset($_SESSION['cityerr'])))
Should work.
Another think I'm advising is to unset the sessions of the errors, in your case I would do that in the end of the Login.php page. Just in case, so there won't be any problems if you fix the form inputs and submit it again.
Another thing, based on the unset idea. If you will do this, it would be much more cleaner way to change the setting of the error sessions instead of:
$_SESSION['cityerr']
to:
$_SESSION['errors']['cityerr']
So afterwards, you can clean the specific form error session in one command, like that:
unset($_SESSION['errors']);
Hope it helped ;)
if(isset($_POST['field_name']))
{
$field_name=$_POST['field_name']
}else
{
unset($_POST['field_name'])
}
I have a registration script (called "script.php") divided in 3 steps; this is the basic structure (i have stripped things out like sanitizing user input and preventing direct access to other steps than 1):
<?php
$step = $_GET['step'];
switch($step) {
case 1:
//show form - action="script.php?step=2" method="post"
break;
case 2:
//if user data is good show an overview of the data and show a button to go to step 3 (the button is enclosed in a form - action="script.php?step=3" and method="post")
//if not, show again form - action="script.php?step=2" method="post" - and display errors
break;
case 3:
//add user data into db
break;
}
?>
Real code:
<?php
switch ($step) {
case 1:
//display form
$html = <<<FORM
<form action="/install?step=2" method="post">
<input type="text" name="username">
<input type="email" name="email">
<input type="password" name="password">
<input type="password" name="password_repeat">
<button class="next" type="submit">Next</button>
</form>
FORM;
break;
case 2:
$errors = array();
if (empty($_POST['username'])||!preg_match_all('/^([A-Za-z0-9]+){1,16}$/', $_POST['username'])) {
$errors[] = 'bad/empty username';
}
if (empty($_POST['email'])||!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errors[] = 'bad/empty email';
}
if (empty($_POST['password'])) {
$errors[] = 'empty password';
}
if (empty($_POST['password_repeat'])) {
$errors[] = 'empty password confirm';
}
if ((!empty($_POST['password'])&&!empty($_POST['password_repeat']))&&$_POST['password']!==$_POST['password_repeat']) {
$errors[] = 'passwords do not match';
}
if(count($errors)>0) {
$error_html = 'some errors occurred';
foreach ($errors as $err) {
$error_html .= 'error: '.$err;
}
$form_html = <<<FORM
<form action="/install?step=2" method="post">
<input type="text" name="username" value="{$_POST['username']}">
<input type="email" name="email" id="email" value="{$_POST['email']}">
<input type="password" name="password">
<input type="password" name="password_repeat">
<button class="next" type="submit">Next</button>
</form>
FORM;
$html = $error_html.$form_html;
}
else {
$ent = 'htmlentities';
$html = <<<DATA_OK
<h3>Data overview</h3>
<table>
<tr>
<th>Username:</th>
<td>{$ent($_POST['username'])}</td>
</tr>
<tr>
<th>email:</th>
<td>{$ent($_POST['email'])}</td>
</tr>
<tr>
<th>Password:</th>
<td>{$ent($_POST['password'])}</td>
</tr>
</table>
<form action="/install?step=3" method="post">
<button class="next" type="submit">Avanti</button>
</form>
DATA_OK;
}
break;
case 3:
//connect to db and insert data
break;
}
?>
<!doctype HTML>
<html>
<head>
<title>Script</title>
<meta charset="utf-8">
</head>
<body>
<?php echo $html; ?>
</body>
</html>
The problem is that when i go to step 3 $_POST is always empty. Is the button shown in step 2 (if user data is good) overwriting $_POST? Or is it emptied because that form has no input but only a submit? How can i pass the $_POST data to step 3 without using hidden fields (as they would contain passwords/pw hashes)?
I have searched on google and here on SO but i couldn't find anything related to my problem.
<form action="/install?step=3" method="post">
<button class="next" type="submit">Avanti</button>
</form>
What values do you expect to be posted in Step 3 ? There is none in your form. Even the button does not have a name attribute. No fields inside a form with name attribute will sent an EMPTY post.
POST data can be disposed the same way as the hidden fields. The one who posts can see what he posts, so there is no reason to hide it from him. If he has posted password from step 1, he knows what he has posted. You can hash it, and set it into a session/hidden fields, even thought it's bad practice.
I, really, don't understand why do you have 2 steps. If step 2 is only having a button, why do you have it? You can make the validation in step 1, and if it is OK, go to step 3, if not - stay.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have a log in page that I want to pass a value to from another page... but it wont pass can anyone help me? please.
login page code:
<!DOCTYPE html>
<?php
ob_start();
session_start();
include('include/connect.php');
?>
<html>
<head>
<title>test</title>
</head>
<body>
<form action="" method="post">
<input type="text" name="username">
<input type="text" name="password">
<input type="submit" name="login" id="send" />
</form>
</body>
</html>
<?php
// Inialize session
if(isset($_POST['login'])){
$username=$_POST['username'];
$password=$_POST['password'];
$repcode=$_POST['repcode'];
// Include database connection settings
include('connection.php');
// Retrieve username and password from database according to user's input
$login = mysql_query("SELECT * FROM users WHERE username = '$username' and password = '$password'");
// Check username and password match
if (mysql_num_rows($login) == 1) {
// Set username session variable
$_SESSION['username'] = $_POST['username'];
$_SESSION['repcode'] = $_POST['repcode'];
// Jump to secured page
$stat = "UPDATE users SET status='login'";
mysql_query($stat);
header('Location: home2.php');
}else {
}
}
?>
page to be passed:
<!DOCTYPE html>
<?php
ob_start();
session_start();
include('include/connect.php');
?>
<html>
<head>
<title>test</title>
</head>
<body>
<form method="get">
<input type="text" name="username" value="<?php echo $_POST['username']; ?> "/>
<input type="text" name="repcode" value="<?php echo $_POST['repcode']; ?> "/>
</form>
</body>
</html>
I want to pass the username and repcode to another page and put it in textboxes. Can anyone help me with this...I'm new in php and still learning.
I don't understand the goal of your code, but you need to use $_SESSION instead of $_POST in the 2nd page if you want to use the values stored in SESSION:
<form method="get" >
<input type="text" name="username" value="<?php echo $_SESSION['username']; ?> "/>
<input type="text" name="repcode" value="<?php echo $_SESSION['repcode']; ?> "/>
</form>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm getting pretty far with my registration script now. This has been such an amazing learning curve for me. As of now I've just finished up some bugs with my user recognition and registration email send outs. I'm having some issues with recovering a password though. At the moment I am just trying to get an email recognised, here is my HTML and PHP:
HTML
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php include "header.php" ?>
<div id="wrapper">
<form method="post" action="">
<h2>Recover Password</h2>
<div id="underline"></div>
<ul>
<li>
<label for="usn">Email : </label>
<input type="text" maxlength="30" required autofocus name="reset" />
</li>
<li class="buttons">
<input type="submit" name="reset" value="Reset Pass" class="xbutton" />
</li>
</ul>
</form>
</div>
</body>
</html>
<?php include "prec.php" ?>
PHP
<?php
if($_POST)
{
if(empty($_POST['reset']))
{
echo 'Please enter all fields';
}
else
{
$email = $_POST['reset'];
$password = $_POST['password'];
$db_name =
$db_user =
$db_pass =
$conn = new PDO('mysql:host=localhost;dbname=tweezy_php', 'tweezy_php', 'XXXXXX',
array( PDO::ATTR_PERSISTENT => true ));
$stmt = $conn->prepare("SELECT email FROM users WHERE email = ? ");
$stmt->execute(array($email));
if($stmt->rowCount() === 1 )
{
echo "That email exists";
}
else
{
echo "Sorry, that email doesn't exsist.";
}
}
}
?>
For some reason, no matter what I enter the supplied email is never recognised. Looking through my code I don't quite see why though. I've tried a couple of variations, but it just seems to give me the same result. I'm thinking it has something to do with my SQL query, but I can't seem to quite put my finger on it.
Any insights would be wonderful!
Your input field is:
<input type="text" maxlength="30" required autofocus name="reset" />
Change this to:
<input type="text" maxlength="30" required autofocus name="email" />
And, in your PHP, you'd do something like this to retrieve the email from the user:
$email = $_POST['email'];
A simple example to demonstrate why it's failing:
test.php
<?php
if(isset($_POST['fieldname'])){
echo $_POST['fieldname']; //outputs "Submit" instead of the user input
}
?>
<form action="" method="post">
<input type="text" name="fieldname"/>
<input type="submit" name="fieldname">
</form>
Both the input field and submit button has the same name. So when you input something and click on submit, you will find that instead of echoing the user input, it echoes the text Submit. This is because the first input is being overridden by the name attribute in your Submit button. This can be resolved by changing your email input's name attribute to something different, like email so it makes more sense.
Hope this helps!
You have two fields in the form that contain name="reset". One is the email field, the other is the submit button.
This will confuse things -- only one of those values will get into your $_POST array, and it looks like it's the wrong one.
You should tidy up the form and ensure that your field name attributes do not clash.
In addition, I note that the email field has a label near it that has for="usn", but there isn't a usn field anywhere to be seen. That won't cause any problems, but is badly incorrect (it looks like a copy+paste bug) -- you probably fix that too.
Change $email to This:
$email = $_POST['username'];
And
if(!isset($_POST['reset']))
Try the following:
$conn = new PDO('mysql:host=localhost;dbname=tweezy_php', 'tweezy_php', 'XXXXXX',
array( PDO::ATTR_PERSISTENT => true ));
$stmt = $conn->prepare("SELECT email FROM users WHERE email = ? ");
$stmt->bindValue(1, $email);
$stmt->execute();
$result = $stmt->fetchAll();
if(count($result) === 1 ){
echo "That email exists";
}else{
echo "Sorry, that email doesn't exsist.";
}
Also, you should change the name of the email's input. It is conflicting with another input and if two inputs have the same name without them being an array, the last input's value will be presented to the server.
That should resolve the issue. Hope this helps.
Your issue is because you're checking the Reset button for a value and not the email field. Here's your email field:
<input type="text" maxlength="30" required autofocus name="username" />
So you need to change this:
if(empty($_POST['reset']))
AND
$email = $_POST['reset'];
To check $_POST['username'] instead.
Both your reset and email input fields are named reset (name="reset"). This will result in the first field (which should be named email) being overriden by your actual reset input field
Change your email input to
<input type="text" maxlength="30" required autofocus name="email" />
And your $email to
$email = $_POST['email'];