If the query fails it gives my the mysql error and stops. So the query is working I'm assuming now I think the problem must be somewhere else in my code.
The mysterious mysql class and function. Downside of this function you can't use mysql_real_escape_string(); or at least I havn't figured out how to get that to work yet since you have to have a db connection established before you can call that function. I suppose I could use pconnect but I really don't like doing that.
class db_call {
var $s = "localhost";
var $db = "*";
var $un = "*";
var $pw = "*";
//Handles all Database query's.
function execute($query){
$link = mysql_connect($this->s, $this->un, $this->pw)or die("Error: " . mysql_error());
mysql_select_db($this->db, $link)or die ("Error: " . mysql_error());
$result = mysql_query($query)or die ("Error: " . mysql_error());
return $result;
}
}
Login function I left out the containing class
//Confirms your a valid user.
function login($email, $password, $ipaddress){
$email = strtolower($email);
$input = array($email, $password);
//Get the salt for AES encryption for MySQL db
$newBox = new db_call;
$salt = $newBox->get_salt();
//Hash's the Password.
$hash = $this->hash_generator($input[0], $input[1]);
$query = sprintf("SELECT is_confirmed FROM user WHERE email = AES_ENCRYPT('%s', '%s') AND password = AES_ENCRYPT('%s', '%s')", $input[0], $salt, $hash, $salt);
$newBox = new db_call;
$result = $newBox->execute($query);
$num_rows = mysql_num_rows($result);
while($row = mysql_fetch_assoc($result)) {
$is_confirmed = $row["is_confirmed"];
}
if ($num_rows == 0){
$query = sprintf("SELECT AES_DECRYPT(email, '%s') FROM attempts WHERE ipaddress = '%s'", $salt, $ipaddress);
$newBox = new db_call;
$result2 = $newBox->execute($query);
$num_rows = mysql_num_rows($result2);
if($num_rows <= 3) {
//Logs failed login attempt
$query = sprintf("INSERT INTO attempts (ipaddress, email) VALUES ('%s', AES_ENCRYPT('%s', '%s'))", $ipaddress, $input[0], $salt);
$newBox = new db_call;
$result3 = $newBox->execute($query);
$feedback = "Your username and password did not match please try again. <br />";
return $feedback;
} else {
$query = sprintf("INSERT INTO banned (ipaddress, email) VALUES ('%s', AES_ENCRYPT('%s', '%s'))", $ipaddress, $input[0], $salt);
$newBox = new db_call;
$result4 = $newBox->execute($query);
$feedback = "Your account has been banned for to many attempted logins. <br />";
return $feedback;
}
}
if($is_confirmed == 1) {
$query = sprintf("SELECT userid FROM user WHERE email = AES_ENCRYPT('%s', '%s') LIMIT 1", $input[0], $salt);
$newBox = new db_call;
$getid = $newBox->execute($query);
while($newrow = mysql_fetch_assoc($getid)){
$userid = $newrow["userid"];
}
$this->user_set_tokens($email, $userid);
$query = sprintf("SELECT AES_DECRYPT(fname, '%s'), AES_DECRYPT(lname, '%s') FROM user WHERE email = AES_ENCRYPT('%s', '%s')", $salt, $salt, $input[0], $salt);
$newBox = new db_call;
$getName = $newBox->execute($query);
while($name = mysql_fetch_assoc($getName)){
$feedback = "<center>Loged in as ".$name["fname"]." ".$name["lname"]."</center>";
}
return $feedback;
} else {
$feedback = "ERROR -- You may not have confirmed your account yet.<br />";
return $feedback;
}
}