Forum Moderators: coopster
$db = new mysqli('$server','$user','$pass','$database');
$db->set_charset('utf8');
$email = $db->real_escape_string(strtolower($user_email));
$password = $db->real_escape_string(md5($salt.$user_pass));
$result = $db->query("SELECT * FROM users WHERE email='$email' AND password='$password'");
if($db->affected_rows===1) while($row = $result->fetch_object()){
$userid = $row->userid;
$userlang = $row->userlang;}
else $error = "Not valid.";
$result->close();
$db->close();
//$id contains the id we search for
$sql = 'SELECT name,price,size FROM widgets WHERE id = ?';
if($stmt = $mysqli->prepare($sql)) {
$stmt->bind_param("s", $id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($name,$price,$size);
if (!$stmt->fetch() ) {
// handle error where the id doesn't exist
}
$stmt->close();
} else {
// handle error where the query can't be prepared
}
// $ref and $ip contain values we want to add to the log table (in the similarly named columns
// both are strings unescaped
$sql='INSERT log (ref, ip) VALUE (?,?)';
if ($stmt = $mysqli->prepare($sql)) {
$stmt->bind_param("ss", $ref, $ip);
$stmt->execute();
$stmt->close();
} else {
//handle error preparing the statement
}
$db = new mysqli('$server', '$user', '$pass', '$database');
$db->set_charset('utf8');
if($stmt = $db->prepare('SELECT userid, userlang FROM users WHERE email=?')){
$stmt->bind_param('s', $email);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($userid, $userlang);
if(!$stmt->fetch()){$error = 'Not valid.';}
$stmt->close();}
$db->close();}
if($stmt = $db->prepare('SELECT userid, userlang FROM users WHERE email=? AND password==SHA256(CONCAT(salt, ?))')){
$stmt->bind_param('ss', $email, $password);
...}
$db = new mysqli('$server','$user','$pass','$database');
$db->set_charset('utf8');
if($stmt = $db->prepare('SELECT userid, userlang, password, salt FROM users WHERE email=?')){
$stmt->bind_param('s', $email);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($userid, $userlang, $password, $salt);
if($stmt->fetch()){
if(hash('sha256', $salt.$_POST['password']) === $password){...}
else $error = 'Password not valid.';}
else $error ='Email address not valid.';
$stmt->close();}
$db->close();