2012-07-26 139 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

相關問題