Hello,
I have been coding little bits and bobs for a little while now. But i have come across a problem that i can't think how i can solve it.
I have a login system form a tutorial online but i would like the use to be able to login with an email address instead of a username. I have managed to get this to work with a basic email like... edd@edd.com, but when i have an email will numbers (e.g. edd123@edd.com) then the login system will not work. I am sure that i have seen some sort of code that stops the input field from affecting the search to MYSQL.
Here is my code...
<?
session_start();
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<?php
if (!isset($_POST['submit'])){
?>
<!-- The HTML login form -->
<center>
<br /><br /><br /><br />
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Email: <br />
<input type="text" name="username" /><br /><br />
Password: <br />
<input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" />
</form>
</center>
<?php
} else {
require_once("db_const.php");
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
# check connection
if ($mysqli->connect_errno) {
echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
exit();
}
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * from traders WHERE pemail LIKE '{$username}' AND password LIKE '{$password}' LIMIT 1";
$result = $mysqli->query($sql);
if (!$result->num_rows == 1) {
echo "<p>Invalid email/password combination</p>";
} else {
$_SESSION['useremail'] = $username;
echo $_SESSION['useremail'];
echo("<h1>Welcome To The TAW Bunker</h1>");
echo "<p>Logged in successfully</p>";
// do stuffs
}
}
?>
</body>
</html>