Ok i know this is the wrong way, i haven't implement salt and other small secure tips but now i need to understand what is the problem here, then i can implement other secure functions to the script, thanks for help :) When run this, the script return Login Error, i can understand why, i print the password $_POST['password'] and it is same on database but when try to print $col2 (the password get from database ) return nothing. Here is the code:
<?php
$mysqli = new mysqli("localhost", "root", "*******", "test");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* prepare statement */
if ($stmt = $mysqli->prepare("SELECT username, password FROM users WHERE username=? AND password=?")) {
$stmt->bind_param("ss" , $username, $password);
$stmt->execute();
/* bind variables to prepared statement */
$stmt->bind_result($col1, $col2);
$stmt->store_result();
/* fetch values */
while ($stmt->fetch()) {
printf("%s %s\n", $col1, $col2);
}
if($col1 && $col2 == $username && $password){
$_SESSION['Admin']; //test - not to be implemented
session_start(); //Test - not to be implemented
header("location index2.php");
}else{echo "Login Error";}
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
?>
$col1 && $col2 == $username && $passwordwhere do you saw this kind of syntax? In fact you haven't provided us info about $username and $password. Where do you get them from? Are $username nad $password the posted values? You are binding them, so it's from the user? How do you declare it?