【问题标题】:3 different code errors3个不同的代码错误
【发布时间】:2013-03-01 00:17:28
【问题描述】:

我的代码中有这 3 个错误。我该如何解决?

警告:mysqli_query() 期望参数 1 为 mysqli,整数 在第 14 行给出 inD:\hosting....\html\template_signupfunctions.php

警告:mysqli_num_rows() 期望参数 1 为 mysqli_result, 在线给出 inD:\hosting....\html\template_signupfunctions.php 的 null 15

警告:mysqli_num_rows() 期望参数 1 为 mysqli_result, 在 D:\hosting....\html\template_signupfunctions.php 中给出的布尔值 第 48 行

警告:mysqli_num_rows() 期望参数 1 为 mysqli_result, 在 D:\hosting....\html\template_signupfunctions.php 中给出的布尔值 第 52 行

这是我的代码。

    session_start();
// If user is logged in, header them away
if(isset($_SESSION["username"])){
    header("location: message.php?msg=NO to that weenis");
    exit();
}

// Ajax calls this NAME CHECK code to execute
if(isset($_POST["usernamecheck"])){
    $db_conx = include_once("php_includes/db_connect.php");
    $username = preg_replace('#[^a-z0-9]#i', '', $_POST['usernamecheck']);
    $sql = "SELECT id FROM users WHERE username='$username' LIMIT 1";
    $query = mysqli_query($db_conx, $sql); 
    $uname_check = mysqli_num_rows($query) ;
    if (strlen($username) < 3 || strlen($username) > 16) {
        echo '<strong style="color:#F00;">3 - 16 characters please</strong>';
        exit();
    }
    if (is_numeric($username[0])) {
        echo '<strong style="color:#F00;">Usernames must begin with a letter</strong>';
        exit();
    }
   if ($uname_check < 1) {
        echo '<strong style="color:#009900;">' . $username . ' is OK</strong>';
        exit();
    } else {
        echo '<strong style="color:#F00;">' . $username . ' is taken</strong>';
        exit();
    }
}

// Ajax calls this REGISTRATION code to execute
if(isset($_POST["u"])){
    // CONNECT TO THE DATABASE
    $db_conx = include_once("php_includes/db_connect.php");
    // GATHER THE POSTED DATA INTO LOCAL VARIABLES
    $u = preg_replace('#[^a-z0-9]#i', '', $_POST['u']);
    $e = mysqli_real_escape_string($db_conx, $_POST['e']);
    $p = $_POST['p'];
    $g = preg_replace('#[^a-z]#', '', $_POST['g']);
    $c = preg_replace('#[^a-z ]#i', '', $_POST['c']);
    // GET USER IP ADDRESS
    $ip = preg_replace('#[^0-9.]#', '', getenv('REMOTE_ADDR'));
    // DUPLICATE DATA CHECKS FOR USERNAME AND EMAIL
    $sql = "SELECT id FROM users WHERE username='$u' LIMIT 1";
    $query = mysqli_query($db_conx, $sql); 
    $u_check = mysqli_num_rows($query);
    // -------------------------------------------
    $sql = "SELECT id FROM users WHERE email='$e' LIMIT 1";
    $query = mysqli_query($db_conx, $sql); 
    $e_check = mysqli_num_rows($query);
    // FORM DATA ERROR HANDLING
    if($u == "" || $e == "" || $p == "" || $g == "" || $c == ""){
        echo "The form submission is missing values.";
        exit();
    } else if ($u_check > 0){ 
        echo "The username you entered is alreay taken";
        exit();
    } else if ($e_check > 0){ 
        echo "That email address is already in use in the system";
        exit();
    } else if (strlen($u) < 3 || strlen($u) > 16) {
        echo "Username must be between 3 and 16 characters";
        exit(); 
    } else if (is_numeric($u[0])) {
        echo 'Username cannot begin with a number';
        exit();
    } else {
    // END FORM DATA ERROR HANDLING
        // Begin Insertion of data into the database
        // Hash the password and apply your own mysterious unique salt
        $cryptpass = crypt($p);
        include_once ("php_includes/randStrGen.php");
        $p_hash = randStrGen(20)."$cryptpass".randStrGen(20);
        // Add user info into the database table for the main site table
        $sql = "INSERT INTO users (username, email, password, gender, country, ip,      signup, lastlogin, notescheck)       
                VALUES('$u','$e','$p_hash','$g','$c','$ip',now(),now(),now())";
        $query = mysqli_query($db_conx, $sql); 
        $uid = mysqli_insert_id($db_conx);
        // Establish their row in the useroptions table
        $sql = "INSERT INTO useroptions (id, username, background) VALUES ('$uid','$u','original')";
        $query = mysqli_query($db_conx, $sql);
        // Create directory(folder) to hold each user's files(pics, MP3s, etc.)
        if (!file_exists("user/$u")) {
            mkdir("user/$u", 0755);
        }
        // Email the user their activation link
        $to = "$e";                          
        $from = "auto_responder@dragonsdengamming.com";
        $subject = 'Dragons Den Gaming Account Activation';
        $message = '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Dragons Den Gaming</title></head><body style="margin:0px; font-family:Tahoma, Geneva, sans-serif;"><div style="padding:10px; background:#333; font-size:24px; color:#CCC;"><a href="http://www.yoursitename.com"><img src="images/logo.png" width="200" height="200" alt="yoursitename" style="border:none; float:left;"></a>yoursitename Account Activation</div><div style="padding:24px; font-size:17px;">Hello '.$u.',<br /><br />Click the link below to activate your account when ready:<br /><br /><a href="http://www.yoursitename.com/activation.php?id='.$uid.'&u='.$u.'&e='.$e.'&p='.$p_hash.'">Click here to activate your account now</a><br /><br />Login after successful activation using your:<br />* E-mail Address: <b>'.$e.'</b></div></body></html>';
        $headers = "From: $from\n";
        $headers .= "MIME-Version: 1.0\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1\n";
        mail($to, $subject, $message, $headers);
        echo "signup_success";
        exit();
    }
    exit();
}

【问题讨论】:

  • 您只需要修复第一个。其他只是后果。这是基本的 PHP 语法问题。
  • 给所有志愿者的提示。它的include 相关问题。

标签: php windows mysqli


【解决方案1】:

好吧,看来问题比我一开始想的更难解决。

include 与您使用它的方式不同。
它不返回任何内容,只是从包含的文件中运行代码。
所以,很可能你必须以这种方式运行它

include_once("php_includes/db_connect.php");

如果您在此文件中设置了$db_conx - 一切都会正常工作。

但还有其他问题

  1. 您没有使用准备好的语句
  2. 您使用的是 mysqli,而必须使用 PDO 代替

【讨论】:

  • 好的,但我仍然收到我发布的错误,不知道为什么,我对 php 很陌生。
  • 修复了一次包含但我仍然有这些错误以及上面列出的错误警告:mysqli_real_escape_string() 期望参数 1 为 mysqli,布尔值在 D:\hosting\10498727\html\template_signupfunctions.php第 39 行警告:mysqli_query() 期望参数 1 为 mysqli,布尔值在 D:\hosting\10498727\html\template_signupfunctions.php 中第 47 行警告:mysqli_query() 期望参数 1 为 mysqli,布尔值在 D: \hosting\10498727\html\template_signupfunctions.php 第 51 行
  • 好的,我修复了 include_once,但仍然有错误消息无法弄清楚如何修复它们我做错了什么我尝试将参数更改为 mysql_results 和其他仍然得到错误消息或者我得到fatel的.可能是因为数据库中没有数据而导致我收到错误消息。 也没有任何数据被放入数据库中
  • $sql = "INSERT INTO 用户(用户名、电子邮件、密码、性别、国家、IP、注册、lastlogin、notescheck)VALUES('$u','$e','$p_hash' ,'$g','$c','$ip',now(),now(),now())"; and$sql = "INSERT INTO useroptions (id, username, background) VALUES ('$uid','$u','original')";
【解决方案2】:

也许您应该看一下有关如何设置数据库连接的手册: http://php.net/manual/de/mysqli.query.php

php_includes/db_connect.php的来源是什么?

【讨论】:

  • db_connect.php 代码 $db_conx = mysqli_connect("ddgusers.db.10498727.hostedresource.com", "ddgusers", "KillingMe30@")OR DIE ("无法连接到数据库!请尝试稍后再试。”); // 评估连接 if (mysqli_connect_errno()) { echo mysqli_connect_error();出口(); }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-19
  • 1970-01-01
  • 1970-01-01
  • 2021-02-25
  • 2021-07-29
  • 2014-01-25
相关资源
最近更新 更多