2012-07-26 136 views
0

按照指示我必须插入代码之间的虚线。 假设刷新并看到'存在' 我有正确的数据库,表,一切都很确定,但我看到 不存在。 我应该继续遵循指南还是我搞砸了?不知道我做了什么错误的PHP登录脚本

有没有人有保证工作的指导,如果我正确地按照它?

我的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

什么错误你是刚开了? – dpitkevics 2012-07-26 11:11:07

+0

你的'die'总是被调用 – madfriend 2012-07-26 11:13:27

+0

那么为什么这个家伙说im应该看到'exists'lol – 2012-07-26 11:14:06

回答

1

die总是被调用,你需要改变你的代码:

if (user_exists('alex') === true) { 
    echo "exists"; 
} 
else{ 
    die('no exist'); 
} 
+0

我相信代码就在那里进行测试。 OP当然需要澄清。 – ghoti 2012-07-26 11:18:35

相关问题