사용자 로그인 페이지 (기본 학습은 PHP로 배우기)를 설정하려고하는데 페이지가 작동하지 않습니다. 행의 수를 계산합니다. (입력 한 로그인 및 암호가 일치하는 user_table 데이터베이스의 행 수가 = 1인지 확인).로그인 페이지에서 FOUND_ROWS 사용
나는 being deprecated 인 mysql_num_rows
을 사용하고 싶지 않거나 적어도 사용하지 않는 것이 좋습니다. 여기에
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>LOGIN PAGE</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>Connect to your account</h1>
<form method="post" action="login_verify.php">
<input type="text" name="inputed_username" size="35" maxlength="30" required="required" value="Enter your login" /><br/><br/>
<input type="password" name="inputed_password" size="35" maxlength="30" required="required" value="Enter your password" /><br/><br/>
<input type="submit" name="submit "value="Connect me !" />
</form>
</body>
</html>
입력 한 {login,password}
이 login_verify.php 파일에 올바른지 내가 확인 PHP 파일입니다 : 대신, 여기 Found_rows
를 사용하려면 나의 login_page.php입니다
당신의 문제는 그것이 좋은 것입니다 자리하고있는 곳을 알고 있다면
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>login process check-up</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
if (isset($_POST['submit']))//if the button submit has not been clicked on
{
try
{
//database connection
$dbhost = "localhost";
$dbname = "test";
$dbuser = "root";
$dbpass = "";
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO("mysql:host=$dbhost;dbname=$dbname; charset=UTF8",$dbuser,$dbpass,$pdo_options);
$bdd -> query('SET NAMES utf8');
//the database is checked to see if there is a match for the couple {user,password}
$user = $_POST['inputed_username'];
$password = $_POST['inputed_password'];
//preparaiton and execution of the request
$req = $bdd->prepare('SELECT * from user_table WHERE login= :login && password= :password LIMIT 1');
$req->execute(array(
'login' => $user,
'password' => $password));
$foundrows = $req->query("SELECT FOUND_ROWS()")->fetchColumn();//the number of rows are counted
//we check if there is a match for the login-password
if ($foundrows == 1)//if we find one that matches
{
session_start();
$_SESSION['username'] = $req['login'];
$_SESSION['fname'] = $req['first_name'];
$_SESSION['lname'] = $req['last_name'];
$_SESSION['logged'] = TRUE;
header("Location: first_page.php");
exit();
}
else //if we don't find any match
{
header("Location: login_page.php");
exit;
}
}
catch (Exception $e)
{
die('Erreur: '.$e->getMessage());
}
}
else //if the submit button has not been clicked on
{
header ("Location: login_page.php");
exit;
}
?>
.
found_rows의 오용으로 인한 것 같습니다. 내가 처음 사용했을 때 나는 무언가를 나쁘게 느꼈지만 그것이 무엇인지는 모르겠다.
이 설명에 대해 감사드립니다. – Mathieu
하지만 my_sql_num_rows를 사용하지 말아야한다는 것을 알았습니다. 공식 웹 사이트에서도 조언을하지 않는다고합니다. http://php.net/manual/en/function.mysql-num-rows.php. 어떻게 생각해 ? – Mathieu
전체 mysql_ * 컴플렉스는 더 이상 사용되지 않지만 단기간에 제거되지는 않습니다. 거기에 waaaaay 너무 많은 코드가 그것을 사용합니다. –