dongmeirang4679 2013-12-26 05:26
浏览 42

有人可以在我的PHP代码中找到错误

I have been looking for a mistake in my php and mysql for the past 5 hours. I have no clue what I have done wrong or if there is just a problem with my mamp. I think it may be a problem with my mamp. This is where I believe the problem would be taking place. But the problem is that now every page comes up blank. Thanks.

site/core/init.php

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

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

      $errors = array();
    ?>

site/core/functions/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;
    }
    ?>

site/includes/widgets/logins

        <aside>         
            <div class = "rightsidebar">
                <h2>Log in/Register</h2>
                <form action = "login.php" method = "post">
                    <ul id = ".login">
                        <li>
                            Username:<br>
                            <input type = "text" name = "username">
                        </li>
                        <li>
                            Password:<br>
                            <input type = "password" name = "password">
                        </li>
                        <li>
                            <input type = "submit" value = "Log In">
                        </li>                                                       
                        <li>
                            <a href = "register.php"><p>Register</p></a>
                        </li>                       
                    </ul>
                </form>
            </div>
        </aside>

site/core/database/connect.php

    <?php
    mysql_connect('localhost', 'root', 'root');
    mysql_select_db('lr');
    ?>

site/core/functions/general.php

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

    ?>

site/login.php

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

    if (user_exists('ben') === true) {
        echo 'exists';
    }
    die();

    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 ca\'nt find that username. Have you registered?';
        }

    }
    ?>
  • 写回答

3条回答 默认 最新

  • drvkf88226 2013-12-26 05:28
    关注

    In query table name and column name should not be wrapped with ' (quot). Either you can use ` or nothing.

    $query = mysql_query("SELECT COUNT(user_id) FROM users WHERE username = '$username'");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab