I am trying to set up a simple php login system with a mysql database and a simple php script. it seems to be working with one minor error; You can also login with the wrong credentials.
You can see it in action at rietool.roxtest.nl.
My code:
<?php
// get values passed from form in login.php file
$username = $_POST['username'];
$password = $_POST['password'];
// to prevent mysql injection
$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// connect to the server and select database
mysql_connect("my database info");
mysql_select_db("roxtest_nl_RIEtool");
// query the database for username
$result = mysql_query("Select * from users where username = '$username' and password = '$password'")
or die ("Failed to query database" .mysql_error());
$row = mysql_fetch_array($result);
if ($row['username'] == $username && $row['password'] == $password) {
echo "login geslaagd, welkom";
} else {
echo "login mislukt, probeer opnieuw";
}
?>
If anyone could help me ou, that would be greatly appreciated!
FYI I followed this tutorial: https://www.youtube.com/watch?v=arqv2YVp_3E