I am very new to mysql . How to validate a user input email value against the value stored in database. The user enters his email in html5 input field and it is to be validated with the values stored in database and perform success actions accordingly. On success navigate to next screen and failure throw a pop up .Attached is screen shot of scenario. [image] (http://s10.postimg.org/5vvlp200p/user_validation.png) Please suggest
EDIT 1:
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp" autocomplete="on">
E-mail: <input type="email" name="email" autocomplete="off"><br>
<input type="submit">
</form>
</body>
</html>
EDIT 2:
<?php
try
{
$connection = mysql_connect("localhost:3306","root","b");
mysql_select_db("MobileBlog", $connection);
mysql_query(" // suggest here to validate against emails in db");
mysql_close($connection);
echo "SUCCESS";
}
catch(Exception $e)
{
echo $e->getMessage();
// Note: Log the error or something
}
?>
EDIT 3 This is my new , HTML5, PHP code , but still failing.
<!DOCTYPE html>
<html>
<body>
<form action="checkform.php" method="post">
E-mail: <input type="email" name="email" autocomplete="off"><br>
<input type="submit">
</form>
</body>
</html>
PHP Code
<?php
try
{
$connection = mysql_connect("localhost:3306","root","b");
mysql_select_db("mobileblog", $connection);
$emailid = $_POST['email'];
echo $emailid;
$sql = "SELECT Name from table WHERE email=" . $_POST['email'];
$result = mysql_query($sql);
echo $result;
if(!$result) { echo "<p class='error'>Error: No such email address</p>"; }
// note that the if is asking if there is no result
else {
while ($row = mysql_fetch_assoc($result)) {
echo "<p class='success'>Welcome " . $row['Name'] . "!!</p>";
}
} // end
//mysql_query(" // suggest here to validate against emails in db");
mysql_close($connection);
echo "SUCCESS";
}
catch(Exception $e)
{
echo $e->getMessage();
// Note: Log the error or something
}
?>
ERROR for edit 3 :
Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\email\checkform.php on line 5
Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in C:\xampp\htdocs\email\checkform.php on line 6 [email protected] Error: No such email address
Warning: mysql_close() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\email\checkform.php on line 32 SUCCESS
SELECT name from table WHERE email=POSTED EMAIL...Nameothers are are notemail. this will get you in trouble in the future when you forget which is which