Salut!
J ai éecrit ces codes mais je ne parviens pas à acceder ma base Myqsl.
Voici le message d erreur:
Parse error: parse error in C:\Apache\htdocs\mypractices\login.php on line 74
la ligne 74 est la toute dernière dans ma page note pad++. Je comprends pas ou se cache l erreur. Quelqu un peut-il me venir en aide.
Merci.
<html>
<head>
<title>Building a Login Form </title>
</head>
<h2>Building a Login Form</h2>
<?php
//if form not yet submitted
//display form
if (!isset($_POST['submit'])) {
?>
<form method="post" action="login.php">
Username:<br/>
<input type="text" name="username"/>
<p>
Password: <br/>
<input type="password" name="password" />
<p>
<input type="submit" name="submit" value="Log In" />
</form>
<?php
//if form submitted
//check supplied login credentials
//against database
} else {
$username = $_POST['username'];
$password = $_POST['password'];
//check input
if (empty($username)) {
die ('ERROR: Please enter your username');
}
if ('ERROR: please enter your password');
}
// attempt database connection
try {
$pdo = new PDO('mysql: dbname=users;host=localhost','yeo', 'yes');
} catch (PDOException $e) {
die ("ERROR: Could not connect: " . $e->getMessage());
}
//escape special characters in input
$username = $pdo->quote($username);
//check if username exists
$sql = "SELECT COUNT(*) FROM users where username = $username";
if ($result = $pdo->query($sql)) {
$row = $result->fetch();
//if yes, fetch the encrypted password
if ($row[0] ==1) {
$sql = "SELECT password FROM users WHERE username = $username";
//encrypt the passord entered into the form
//test it against the encrypted password stored in the database
//if the two match, the password is correct
if ($result = $pdo->query($sql)) {
$row = $result ->fetch();
$salt = $row[0];
if (crypt($password, $salt) == $salt) {
echo 'Your login credentials were successfully.';
} else {
echo 'You entered an incorrect password.';
}
} else {
echo "ERROR: Could not execute $sql. " . print_r ($pdo->errorInfo());
}
//close connection
unset($pdo);
}
?>
</html>
Étudiant
PHP le revolutionnaire, PHP le Conquérant