2014-10-11 65 views
0

我正在按照本教程创建我正在使用的注册数据库。我回过头来看视频,然后看着评论,试图找到解决我的问题的方法。mysql错误显示不正确

我遇到的问题是,我设置的错误不能正确显示我的数据库。我有一个用户名为'lowheartrate',但是当我把它放在用户名字段中并尝试用它登录时,它告诉我我的其他错误之一,
“我们找不到那个用户名。注册?”

很高兴有效,但我需要其他人的工作。特别是不能工作了的有以下错误:

The 'user_active' error. 

    The 'user_exists' error. 

这是与我有问题附属代码:

我的login.php它显示了代码的错误: enter image description here

是他们连接在一起,并告诉它做的users.php代码: enter image description here

的general.php: enter image description here

的的init.php:
enter image description here

在users.php更好看:

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

function user_active($username) { 
    $username = sanitize ($username); 
    return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `active` = 1"), 0) == 1) ? true : false; 
    } 
?> 

在login.php中更好看:

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

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\'t find that username. Have you registered?'; 
    } else if (user_active($username) == false) { 
     $errors[] = 'You haven\'t activated your account.'; 
    } else { 
     // here 
    } 

    print_r($errors); 
} 
?> 

一个更好看的init.php:

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

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

$errors = array(); 
?> 

一个更好的看general.php:

<?php 
function sanitize($data) { 
    return mysql_real_escape_string($data); 
} 
?> 

一个更好的看connect.php:

<?php 
$connect_error = 'Sorry we\'re experiencing connection issues.'; 
$con = mysqli_connect('localhost','root',''); 
mysqli_select_db($con,'lr') or die($connect_error); 
?> 

一看表(登录。PHP的小部件):

<div class="widget">  
    <h2>Returning Member?</h2> 
    <div class="inner"> 

     <form action="login.php" method="post"> 
      <ul id="login"> 
       <li> 
        <input type="text" name="username" placeholder="Username" autofocus > 
       </li> 

       <li> 
        <input type="password" name="password" placeholder="Password" > 
       </li> 

       <li> 
        <input type="submit" value="Log in" > 
       </li> 

       <li> 
        <a href="register.php">Create an Account</a> 
       </li> 
      </ul> 
     </form> 

    </div> 
</div> 

不知道它的问题,但在此处,它被显示在index.php:

<?php 
$pageTitle = 'gLounge - Welcome to gLounge!'; 
include('includes/php/header.php'); 
?> 

      <!-- Middle content section --> 
      <div class="middle"> 
       <div class="container"> 
        <div class="col-md-9 content"> 
         <h2>Use gLounge42 as your new source to connect with fellow gamers. We have plenty for you to look at.</h2> 
         <p> 

          gLounge42 allows all types of gamers on all types of consoles/platforms connect with each other with 
          unlimited amount of reasons to do so. Here at gLounge42 you can chat with them and go as far as posting 
          in forums to get members for you Call of Duty clan. Possibilities are endless so go ahead and get your 
          account setup now with gLounge42! 

         </p> 
         <div class="to-tutorial"> 
          <p><strong>Register an Account to get started:</strong></p> 
          <a href="register.php" class="btn btn-success">Register</a> 
         </div> 
        </div> 
        <!-- Includes the login widget on the top right side of page --> 
       <?php include('includes/widgets/login.php');?> 
        <!-- Includes the side navigation area --> 
       <?php include('includes/php/sideNavigation.php');?> 
       </div> 
      </div> 
<?php 
include('includes/php/footer.php') 
?>  

数据库的元素,我正在使用:

enter image description here

连接到数据库中的用户:

enter image description here

如果需要任何更多信息,请让我知道。
此致敬礼,
科迪

+0

@ Arif_suhail_123我仍然得到同样的错误,当我用2代替3 '=' 代替的迹象。没有拿起user_active不幸 – cscodismith 2014-10-11 05:31:42

+0

@ Arif_suhail_123是的,仍然没有找到我的解决方案。会爱你的输入请 – cscodismith 2014-10-11 06:21:38

+0

@ Arif_suhail_123当我添加你给我的代码并继续到login.php它没有任何错误代码什么都不是什么好事,因为我继续登录login.php,甚至没有把一个用户名或密码,它并没有给我一个错误代码。 – cscodismith 2014-10-11 06:32:42

回答

0

的init.php

<?php 
session_start(); 
error_reporting(E_ALL);//I change this line always use this. During 
//the production. after you finish you can change it. 

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

$errors = array(); 
?> 

阅读评论,任何你发现他们的答案。 Connect.php

<?php 
//Your were mixing the mysqli and mysql, here you are using mysqli_ function But method you are 
//using msysql one so change it to mysql function 



$connect_error = 'Sorry we\'re experiencing connection issues.'; 
$con = mysql_connect('localhost','root',''); 
mysql_select_db('lr',$con) or die($connect_error);//Database name should be first 
?> 

users.php

<?php 

require 'database/connect.php';//You were missing connection here. 
function user_exists($username) { 
    $username = sanitize ($username); 
    echo $username; 
    //$result=or die(mysql_error()); 

    if(mysql_num_rows(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"))==1)  return TRUE; else  return FALSE; 
    //if(mysql_num_rows(mysql_query()== 1)) 
    } 

function user_active($username) { 
    $username = sanitize ($username); 
if(mysql_num_rows(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username' AND `active`='1'"))==1)  return TRUE; else  return FALSE; } 
?> 
0

首先停止使用mysql的首要。对准备好的语句或PDO使用mysqli_ *函数。

你在login.php中的if语句看起来不错。尝试在user.php中使用它:

$bool = (mysql_num_rows(mysql_query("your query")) == 1) ? true : false; 

现在您检查已返回的行数。而且我不确定你是否可以在回报中加入if语句。所以,现在你做的事:

Return $bool; 
+0

好的,谢谢。对不起,我只是不想再搞砸了。我把$ bool =(mysql_num_rows(mysql_query(“你的查询”))== 1)?真假;在最上面一行还是最下面一行!?你想让我把你的回报$ bool放在哪里? ??如果你能给我线条,那将会很棒! – cscodismith 2014-10-11 05:45:01

+0

Put $ bool =(mysql_num_rows(mysql_query(“your query”))== 1)?真假;在user.php中的return语句中,并用return来替换你现有的return语句$ bool – andy 2014-10-11 05:52:21

+0

我目前有两个返回语句,我感到困惑的是每个语句的放置位置,目前我没有收到任何错误或任何显示被定向到login.php - 它只是白色,没有内容,所以如此。 – cscodismith 2014-10-11 05:57:40