2016-06-06 3 views
-1

내가 직면하고있는 문제는 내 Preg_Match 유효성 검사가 전혀 작동하지 않는다는 것입니다. 내가해야 할 일은 로그인 버튼을 클릭하고 로그인하는 것입니다. 사용자가 아무 것도 남기지 않거나 오류가 발생하면 유효성 검사가 오류를 선택하고 적절한 오류 메시지를 표시해야합니다. 여기 Preg_Match Validation이있는 PHP 로그인 페이지

는 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

0 내 코드

입니다

<!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"; } } ?> 
+2

정확히 50 진수 숫자가 될? 어떻게 그걸 생각해 냈어? – mario

+0

우리가 만든 데이터베이스에서 phpMyAdmin @ 마리오에서 길이가 50입니다. – DevAnon

+1

'PHPMyAdmin'에서 볼 수있는 숫자는 최소 또는 정확한 길이가 아닌 최대 길이입니다. – Peter

답변