Note: I am German. So some irrelevant text is in german like e.g. some php echo messages.
Probably it is only a beginner mistake. But I searched all night long and did not find an answer to my problem. I hope you can help me.
I want to create a php login script with XXAMP and its mysql-database. I created a database via phpmyadmin.
[Here could be an image of this database] - But: "You need at least 10 reputation to post images." Sry.
Then I worked on the login.php script. It looks so:
<?php
session_start();
?>
<?php
$verbindung = mysql_connect("127.0.0.1", "myname" , "mypassword")
or die("Verbindung zur Datenbank konnte nicht hergestellt werden");
mysql_select_db("homepage") or die ("Datenbank konnte nicht ausgewählt werden");
$username = $_POST["username"];
$password = md5($_POST["password"]);
$abfrage = "SELECT username, password FROM access WHERE username LIKE '$username' LIMIT 1";
$ergebnis = mysql_query($abfrage);
$row = mysql_fetch_object($ergebnis);
// $count = mysql_num_rows($ergebnis);
if($row->password == $password) {
$_SESSION["username"] = $username;
echo "Login erfolgreich. <br> <a href=\"home.php\">Weiter</a>";
}
else {
echo "Benutzername und/oder Passwort waren falsch. <a href=\"index.htm\">Login</a>";
}
?>
I already tested the connection to the database in a separate php file. It works.
But when I try to login on my index.htm:
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="login.php" method="post">
<input type="text" size="24" maxlength="50" name="username"<br>
<input type="password" size="24" maxlength="50" name="password"<br>
<input type="submit" value="Login">
</form>
</body>
</html>
I get the answer on login.php:
password == $password) { $_SESSION["username"] = $username; echo "Login erfolgreich. Weiter"; } else { echo "Benutzername und/oder Passwort waren falsch. Login"; } ?>
I tried so much things, but nothing helped.
Maybe you have an idea why it does not work?
I would be very grateful.
>ofif($row->. my guess is that php is not running, as it possibly assumes it is html code, and that is the closing tag of<?php.