0

按照指示,我必须在虚线之间插入代码。应该刷新并查看“存在”我有正确的数据库、表,我很确定一切,但我认为不存在。我应该继续遵循指南还是我搞砸了?

如果我正确地遵循它,是否有人有保证工作的指南?

我的 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,我会按照他的指南进行操作

4

1 回答 1

1

die总是被调用,你应该将你的代码更改为:

if (user_exists('alex') === true) {
    echo "exists";
}
else{
   die('no exist');
}
于 2012-07-26T11:15:10.493 回答