不知道我做错了什么错误的php登录脚本

时间:2012-07-26 11:10:13

标签: php mysql login phpmyadmin

按照说明我必须在虚线之间插入代码。 假设刷新并看到'存在' 我有正确的数据库,表,一切我非常肯定但是 我看不存在。 我应该继续遵循指南还是我搞砸了?

如果我正确地遵循它,是否有人有保证可以使用的指南?

我的login.php

<?php
include 'core/init.php';

-----------------------------------------
if (user_exists('alex') === true) {
echo "exists";
}
die('no exist');
-------------------------------------------
if (empty($_POST) === false) {
    $username = $_POST['username'];
    $password = $_POST['password'];

    if (empty($username) === true || empty($password) === true) {
        $errors[] = 'You need to enter a username and password';
    } else if (user_exists($username) === false) {
        $errors[] = 'We can not find that user';
    }
}
    ?>

我有init.php

<?php
session_start();
error_reporting(0);

require 'database/connect.php';
require 'functions/general.php';
require 'functions/users.php';

$errors = array();
?>

我有users.php

<?php
function user_exists($username) {
    $username = sanitize($username);
    $query = mysql_query("SELECT COUNT('user_id') FROM 'users' WHERE 'username' = '$username'");
    return (mysql_result($query, 0) == 1) ? true : false;
}
?>

i have general.php
<?php
function sanitize($data) {
    return mysql_real_escape_string($data);
}
?>

我用:

<form action="login.php" method="post">

注意:如果有人熟悉phpacademy,我正在关注他的指南

1 个答案:

答案 0 :(得分:1)

您的die始终被调用,您应该将代码更改为:

if (user_exists('alex') === true) {
    echo "exists";
}
else{
   die('no exist');
}
相关问题