em đang học lập trình php và có thực hành theo tài liệu "Sử dụng PHP & MySQL thiết kế web động",nhưng em đang gặp 1 chút vấn đề về file đăng nhập,chả là em tạo thành công file đăng ký và đã đăng ký thành công,acc được lưu vào CSDL nhưng khi em tạo file đăng nhập thì không thểlog vào dc,mặc dù là em đã điền đúng thông tin mà nó toàn báo là tên đăng nhập và mật khẩu không khớp với csdl,em tạo thêm 1 file đổi pass nó cũng không hoạt động chỉ toàn báo lỗi không khớp với CSDL Đây là file dang ky: <?php $page_title = 'Dang ky'; include ('templates/header.inc'); if (isset($_POST['submit'])) { require_once('C:\AppServ\www\new2\mysql_connect.php'); function escape_data($data) { global $dbc; if(ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } return mysql_real_escape_string($data,$dbc); } $message = NULL; if (empty($_POST['first_name'])) { $fn = FALSE; $message .= '<p>Ban chua nhap ten ho!</p>'; } else { $fn = escape_data($_POST['first_name']); } if(empty($_POST['last_name'])) { $ln = FALSE; $message .= '<p>Ban chua nhap ten!</p>'; } else { $ln = escape_data($_POST['last_name']); } if(empty($_POST['email'])) { $e = FALSE; $message .= '<p>Ban chua nhap dia chi thu dien tu!</p>'; } else { $e = escape_data($_POST['email']); } if(empty($_POST['username'])) { $u = FALSE; $message .= '<p>Ban chua nhap ten dang ky</p>'; } else { $u = escape_data($_POST['username']); } if(empty($_POST['password1'])) { $p = FALSE; $message .= '<p>Ban chua nhap mat khau</p>'; } else { if($_POST['password1'] == $_POST['password2']) { $p = escape_data($_POST['password1']); } else { $p = FALSE; $message .= '<p>Mat khau khong khop voi phan xac nhan!</p>'; } } if($fn && $ln && $e && $u && $p) { $query = "SELECT user_id FROM users WHERE username = '$u'"; $result = @mysql_query ($query); if(mysql_num_rows ($result) == 0) { $query = "INSERT INTO users (username,first_name,last_name,email,password,registration_date) VALUES ('$u','$fn','$ln','$e',PASSWORD('$p'),NOW())"; $result = @mysql_query ($query); if ($result) { echo '<p><b>Ban da duoc dang ky!</b></p>'; include ('templates/footer.inc'); exit(); } else { $message = '<p>Ban khong the dang ky do mot loi he thong.Chung toi xin loi vi su co nay.</p><p>'. mysql_error() . '</p>'; } } else { $message = '<p>Ten dang nhap nay da duoc dang ky.</p>'; } mysql_close(); } else { $message .= '<p>Hay thu lai.</p>'; } } if(isset($message)) { echo '<font color = "red">', $message, '</font>'; } ?> <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method = "post"> <fieldset><legend>Nhap vao thong tin cua ban:</legend> <p><b>Ten ho:</b><input type = "text" name = "first_name" size = "15" maxlength = "15" value = "<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p><b>Ten:</b><input type = "text" name = "last_name" size = "30" maxlength = "30" value = "<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p><b>Email:</b><input type = "text" name = "email" size = "40" maxlength = "40" value = "<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p><b>Ten dang nhap:</b><input type = "text" name = "username" size = "10" maxlength = "20" value = "<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p> <p><b>Mat khau:</b><input type = "password" name = "password1" size = "20" maxlength = "20" /></p> <p><b>Xac nhan:</b><input type = "password" name = "password2" size = "20" maxlength = "20" /></p> </fieldset> <div align = "center"><input type = "submit" name = "submit" value = "Dang ky" /></div> </form> <?php include ('templates/footer.inc'); ?> Đây là file đăng nhập <?php if(isset($_POST['submit'])) { require_once('C:\AppServ\www\new2\mysql_connect.php'); function escape_data($data) { global $dbc; if(ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } return mysql_real_escape_string($data,$dbc); } $message = NULL; if(empty($_POST['username'])) { $u = FALSE; $message .= '<p>Ban chua nhap ten dang nhap!</p>'; } else { $u = escape_data ($_POST['username']); } if (empty($_POST['password'])) { $p = FALSE; $message .= '<p>Ban chua nhap mat khau</p>'; } else { $p = escape_data($_POST['password']); } if ($u && $p) { $query = "SELECT user_id,first_name FROM users WHERE username ='$u' AND password =PASSWORD('$p')"; $result = @mysql_query($query); $row = mysql_fetch_array($result,MYSQL_NUM); if ($row) { session_name ('YourVisitID'); session_set_cookie_params(900); session_start(); $_SESSION['first_name'] = $row[1]; $_SESSION['user_id'] = $row[0]; header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/loggedin.php"); exit(); } else { $message = '<p>Ten dang nhap va mat khau khong phu hop voi du lieu trong csdl.</p>'; } mysql_close(); } else { $message .= '<p>Hay thu lai.</p>'; } } $page_title = 'Login'; include ('templates/header.inc'); if (isset($message)) { echo '<font color = "red">',$message,'</font>'; } ?> <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method = "post"> <fieldset><legend>Nhap vao thong tin cua ban:</legend> <p><b>Ten dang nhap:</b><input type = "text" name = "username" size = "10" maxlength = "20" value = "<?php if(isset($_POST['username'])) echo $_POST['username'];?>"/></p> <p><b>Mat khau:</b><input type = "password" name = "password" size = "20" maxlength = "20" /></p> <div align = "center"><input type = "submit" name = "submit" value = "dang nhap"/></div> </fieldset></form> <?php include('templates/footer.inc'); ?> Đây là file đổi pass <?php $page_title = 'Thay doi mat khau.'; include ('templates/header.inc'); if (isset($_POST['submit'])) { require_once ('C:\AppServ\www\new2\mysql_connect.php'); function escape_data($data) { global $dbc; if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } return mysql_real_escape_string($data,$dbc); } $message = NULL; if (empty($_POST['username'])) { $u = FALSE; $message .= '<p>Ban chua nhap ten dang ky</p>'; } else { $u = escape_data($_POST['username']); } if (empty($_POST['password'])) { $p = FALSE; $message .= '<p>Ban chua nhap mat khau hien tai!</p>'; } else { $p = escape_data($_POST['password']); } if (empty($_POST['password1'])) { $np = FALSE; $message .= '<p>Ban chua nhap mat khau moi!</p>'; } else { if ($_POST['password1'] == $_POST['password2']) { $np = escape_data($_POST['password1']); } else { $np = FALSE; $message .= '<p>Mat khau moi khong khop voi gia tri xac nhan!</p>'; } } if ($u && $p && $np) { $query = "SELECT user_id FROM users WHERE (username = '$u' AND password = PASSWORD('$p'))"; $result = @mysql_query ($query); $num = mysql_num_rows ($result); if ($num == 1) { $row = mysql_fetch_array($result , MYSQL_NUM); $query = "UPDATE users SET password = PASSWORD('$np') WHERE user_id = $row[0]"; $result = @mysql_query ($query); if (mysql_affected_rows() == 1) { echo '<p><b>Mat khau da duoc thay doi thanh cong.</b></p>'; include ('templates/footer.inc'); exit(); } else { $message = '<p>Mat khau cua ban khong the thay doi vi loi he thong.Chung toi xin loi vi su co nay.</p><p>' . mysql_error() . '</p>'; } } else { $message = '<p>Ten dang nhap va mat khau cua ban khong dung voi cac mau tin trong csdl.</p>'; } mysql_close(); } else { $message .= '<p>Hay thu lai.</p>'; } } if (isset($message)) { echo '<font color = "red">', $message,'</font>'; } ?> <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method = "post"> <fieldset><legend>Nhap vao thong tin cua ban:</legend> <p><b>Ten dang nhap:</b><input type = "text" name = "username" size = "10" maxlength = "20" value = "<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p> <p><b>Mat khau hien tai:</b><input type = "password" name = "password" size = "20" maxlength = "20" /></p> <p><b>Mat khau moi:</b><input type = "password" name = "password1" size = "20" maxlength = "20" /></p> <p><b>Xac nhan:</b><input type = "password" name = "password2" size = "20" maxlength = "20" /></p> </fieldset> <div align = "center"><input type = "submit" name = "submit" value = "Thay doi mat khau" /></div> </form> <?php include ('templates/footer.inc'); ?>