Das Problem, mit dem ich konfrontiert bin, ist, dass meine Preg_Match Validierung überhaupt nicht funktioniert. Alles, was ich tun muss, ist klicken Sie auf die Login-Schaltfläche und es meldet sich an. Ich brauche es zu sein, wenn der Benutzer nichts leer lässt oder einen Fehler macht, die Validierung den Fehler aufnimmt und die entsprechende Fehlermeldung anzeigt.PHP Login-Seite mit Preg_Match Validierung
Hier ist mein Code
Index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<html>
<head>
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<?php
if (!isset($_POST['submit'])){
?>
<!-- The HTML login form -->
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Email:<br>
<input type="text" name="email" /><br />
Password:<br>
<input type="password" name="password" /><br /><br/>
<input type="submit" name="submit" value="Login" />
<a href="Register.php"/>Sign Up</a>
</form>
<?php
} else {
include("DBConn.php");
mysqli_connect("localhost","root","","test");
$email = $_POST['email'];
$password = $_POST['password'];
if(!$email)
{
echo('Enter an email');
}
elseif(!preg_match('/^[a-z0-9][email protected][a-z\.]+$/i', $email))
{
echo('Enter a valid email');
}
if(preg_match('/^[0-9a-f]{50}$/', $password)) {
echo 'The password does not meet the requirements!';
}
$sql = "SELECT * FROM tbl_user WHERE Email LIKE '{$email}' AND Password LIKE '{$password}' LIMIT 1";
$result = mysqli_query($DBConnect,$sql);
if (!$result == 1) {
echo "<p>Invalid email/password combination</p>";
} else {
echo "<p> Users Email is: $email</p>";
echo "<p> Users Password is: $password </p>";
echo "<p> Users Encrypted Password is: '".md5($password)."'</p>";
echo"<p>Logged in successfully</p>";
?>
<a href="Item.php"/>Click here to go to Store.</a>
<?php
}
}
?>
</body>
</html>
DBConn.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Connect to DB</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
$DBName = "Test";
$DBConnect = mysqli_connect ("127.0.0.1","root","","test");
if($DBConnect === FALSE)
echo "<p> Connection Failed /<p>\n";
else {
echo "<p> Successfully connected to the " . "\"$DBName\" database . </p>\n";
}
?>
</body>
</html>
CreateTable.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Create Table</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
include("DBConn.php");
$TableName = "tbl_User";
$SQLString = "SHOW TABLES LIKE '$TableName'";
$QueryResult = mysqli_query($DBConnect,$SQLString);
$FileName = 'userData.csv';
if($QueryResult = mysqli_query($DBConnect,$SQLString))
{
$numRows = mysqli_num_rows($QueryResult);
}
if($numRows == 0)
echo "<p> This table does not exist and will be created now. ";
else
{
$SQLString = "DROP TABLE tbl_User";
$QueryResult = mysqli_query($DBConnect,$SQLString);
if($QueryResult === FALSE)
echo "<p> Table already exsits</p>";
else
echo "<p> Successfully deleted the table.</p>";
}
if($numRows == 0)
{
$SQLString = "CREATE TABLE tbl_User (ID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY,FirstName VARCHAR(50),LastName VARCHAR(50),Email VARCHAR(50),Password VARCHAR(50))";
$QueryResult = mysqli_query($DBConnect , $SQLString);
if($QueryResult === FALSE)
echo "<p> Unable to create the tbl_User table. </p>" . "<p> Error Code" .
mysqli_errno($DBConnect) . ":" . mysqli_error($DBConnect) . "</p>";
else
echo "<p> Successfully created the tbl_User table.</p>";
}
if(file_exists($FileName))
{
echo "\nFile Exits";
$twoDarray = array();
if (($handle = fopen("userData.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$twoDarray[] = $data;
}
echo "<pre>\n";
print_r(array_filter($twoDarray[$data]));
echo "</pre>";
foreach($twoDarray as $rows)
{
$SQLString = "INSERT INTO tbl_User(FirstName,LastName,Email,Password) VALUES ('$rows[0]','$rows[1]','$rows[2]','$rows[3]')";
$QueryResult = mysqli_query($DBConnect,$SQLString);
}
fclose($handle);
}
else {
echo "\nFile does not exsits, Wrong path";
}
}
?>
Das Passwort genau 50 Hex-Zahlen sein muss? Wie kommst du auf sowas? – mario
In der Datenbank, die wir erstellt haben, war es eine Länge von 50 in phpMyAdmin @ mario – DevAnon
Die Zahl, die Sie in 'PHPMyAdmin' sehen, ist eine maximale Länge, keine minimale oder genaue Länge. – Peter