Reputation: 29
I can't figure out why I get this error on my process.php page:
Connected successfully
Could not run query: Table 'members_db.members where 'email' = '123456789'' doesn't exist
Invalid query: Duplicate entry '123456789' for key 'email'
Doesn't make much sense, as it seems to be contradicting itself in the error message.
Here my process.php:
<?php
session_start();
$con = mysql_connect('localhost', 'root', '');
if (!$con) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br />';
// make members the current db
$db_selected = mysql_select_db('members_db', $con);
if (!$db_selected) {
die ('Can\'t use members database : ' . mysql_error());
}
$hash_password = md5($_POST['password']);
$email = $_POST['email'];
$result = mysql_query("SELECT email,password FROM `members WHERE 'email' = '$email'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
$query = "INSERT INTO members (email, password)
VALUES('".$_POST['email']."','".$hash_password."')";
// Perform Query
$result2 = mysql_query($query);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result2) {
$message = 'Invalid query: ' . mysql_error() . "\n";
//$message .= 'Whole query: ' . $query;
die($message);
}
$_SESSION['email']=$_POST['email'];
$_SESSION['password']=$hash_password;
$_SESSION['loggedin']="YES";
$url = "Location: /welcome.php";
header($url);
}
$_SESSION['email']=$_POST['email'];
$_SESSION['password']=$hash_password;
$url = "Location: /checklogin.php";
header($url);
?>
It's probably a stupid error, as I'm learning while working on this project. Thanks for any help!
Upvotes: 0
Views: 283
Reputation: 312
For the first error:
Change the first query
$result = mysql_query("SELECT email,password FROM `members WHERE 'email' = '$email'");
to
$result = mysql_query("SELECT email,password FROM `members` WHERE email = '$email'");
Second error:
The 'Duplicate entry' is because you already have an email with the same data and your 'email' column is unique, just delete the members row with email = 123456789.
Upvotes: 0
Reputation: 24825
"SELECT email,password FROM `members WHERE 'email' = '$email'"
"SELECT email,password FROM `members` WHERE 'email' = '$email'"
you missed a backtick => `
Upvotes: 5
Reputation: 483
Change
"SELECT email,password FROM `members WHERE 'email' = '$email'"
to
"SELECT email,password FROM `members` WHERE 'email' = '$email'"
Upvotes: 0