I have been working on a script for a login form but the sql will not run to the database, now its been years since I have worked with php and mysql so I am a little rusty but I can not see the bug, I am sure it is small.
Anyway what happens is that I try to run the query and my site gos to the "or die" part of the code and so says could not run query, so I know its "talking to the DB" so its something to do with the query, any ideas below is the code.
<form action="#" method="post" id="loginform">
<label>e-mail<input type="email" name="email" /></label><br />
<label>password<input type="password" name="pass" /></label><br />
<input type="submit" class="button" value="Log In" name="submit" />
</form>
<?php
if(isset($_POST['submit'])){
$email = $_POST['email'];
$pass = $_POST['pass'];
$con = mysqli_connect('localhost','root','') or die ('Could not connect to databace');
mysqli_select_db($con, 'mysitesdb');
$query = mysqli_query($con, 'SELECT * FROM users WHERE email="$email" AND pass="$pass"') or die ('Could not run query');
$result = mysql_result($query, 0);
echo 'result = '.$result;
mysqli_close($con);
if($result != 1){
echo "More than one record found";
}else{
echo "Log in done";
$_SESSION['email'] = $email;
}
}
?>
- <form action="#" method="post" id="loginform">
- <label>e-mail<input type="email" name="email" /></label><br />
- <label>password<input type="password" name="pass" /></label><br />
- <input type="submit" class="button" value="Log In" name="submit" />
- </form>
- <?php
- if(isset($_POST['submit'])){
- $email = $_POST['email'];
- $pass = $_POST['pass'];
-
- $con = mysqli_connect('localhost','root','') or die ('Could not connect to databace');
- mysqli_select_db($con, 'mysitesdb');
-
- $query = mysqli_query($con, 'SELECT * FROM users WHERE email="$email" AND pass="$pass"') or die ('Could not run query');
- $result = mysql_result($query, 0);
- echo 'result = '.$result;
-
- mysqli_close($con);
-
- if($result != 1){
- echo "More than one record found";
- }else{
- echo "Log in done";
- $_SESSION['email'] = $email;
- }
- }
- ?>
^__^