Php 警告:mysqli_query()要求参数1为mysqli,字符串为给定值

Php 警告:mysqli_query()要求参数1为mysqli,字符串为给定值,php,mysql,mysqli,Php,Mysql,Mysqli,首先,我要说的是,我在这里和其他网站上读到了大约15条类似的帖子,试图在发布之前解决我的问题 我正在用一些php和mysql测试一个站点。一些信息: 我构建了本地托管的站点,然后将其导出到webhost。为了测试php和mysql函数,这是必要的吗?我在本地有一个mysql数据库。这会导致问题吗 我有两个问题 在运行任何php脚本的页面上,我都会收到以下警告: 警告:出于安全原因,已在第2行的/home/a2575478/public_html/Login.php中禁用了virtual() 警告

首先,我要说的是,我在这里和其他网站上读到了大约15条类似的帖子,试图在发布之前解决我的问题

我正在用一些php和mysql测试一个站点。一些信息:

我构建了本地托管的站点,然后将其导出到webhost。为了测试php和mysql函数,这是必要的吗?我在本地有一个mysql数据库。这会导致问题吗

我有两个问题

  • 在运行任何php脚本的页面上,我都会收到以下警告:
  • 警告:出于安全原因,已在第2行的/home/a2575478/public_html/Login.php中禁用了virtual()

    警告:mysqli_query()要求参数1为mysqli,在第37行的/home/a2575478/public_html/Login.php中给出空值

    警告:mysqli_error()要求参数1为mysqli,在第37行的/home/a2575478/public_html/Login.php中给出空值

    我知道这些警告与不推荐使用的mysql_*函数有关,但我在修复不推荐使用的函数时遇到了问题

    二,

    现在,当我尝试在本地访问网页时,我得到的只是一个“网页不可用”错误。这是由于错误造成的还是只是试图在本地运行php

    该站点是可访问的

    如果你需要更多的信息,请告诉我

    代码如下

    Login.php

        <?php @session_start(); ?>
        <?php virtual('/Connections/logincon.php'); ?>
        <?php
        if (!function_exists("GetSQLValueString")) {
        function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
        {
          if (PHP_VERSION < 6) {
            $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
          }
    
          $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
          switch ($theType) {
            case "text":
              $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
              break;    
            case "long":
            case "int":
              $theValue = ($theValue != "") ? intval($theValue) : "NULL";
              break;
            case "double":
              $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
              break;
            case "date":
              $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
              break;
            case "defined":
              $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
              break;
          }
          return $theValue;
        }
        }
    
    
        $query_Login = "SELECT * FROM `user`";
        $Login = mysqli_query($logincon,$query_Login) or die(mysqli_error($logincon));
        $row_Login = mysql_fetch_assoc($Login);
        $totalRows_Login = mysql_num_rows($Login);
        mysqli_select_db($database_logincon, $logincon);
        ?>
        <?php
        // *** Validate request to login to this site.
        if (!isset($_SESSION)) {
          session_start();
        }
    
        $loginFormAction = $_SERVER['PHP_SELF'];
        if (isset($_GET['accesscheck'])) {
          $_SESSION['PrevUrl'] = $_GET['accesscheck'];
        }
    
        if (isset($_POST['Username'])) {
          $loginUsername=$_POST['Username'];
          $password=$_POST['Password'];
          $MM_fldUserAuthorization = "UserLevel";
          $MM_redirectLoginSuccess = "/Account.php";
          $MM_redirectLoginFailed = "/Login.php";
          $MM_redirecttoReferrer = true;
          mysql_select_db($database_logincon, $logincon);
    
          $LoginRS__query=sprintf("SELECT Username, Password, UserLevel FROM `user` WHERE Username=%s AND Password=%s",
          GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
    
          $LoginRS = mysql_query($LoginRS__query, $logincon) or die(mysql_error());
          $loginFoundUser = mysql_num_rows($LoginRS);
          if ($loginFoundUser) {
    
        $loginStrGroup  = mysql_result($LoginRS,0,'UserLevel');
    
        if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
        //declare two session variables and assign them
        $_SESSION['MM_Username'] = $loginUsername;
        $_SESSION['MM_UserGroup'] = $loginStrGroup;       
    
        if (isset($_SESSION['PrevUrl']) && true) {
          $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
        }
        header("Location: " . $MM_redirectLoginSuccess );
      }
      else {
        header("Location: ". $MM_redirectLoginFailed );
      }
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <link href="CSS/Layout.css" rel="stylesheet" type="text/css"  />
    <link href="CSS/Menu.css" rel="stylesheet" type="text/css"  />
    <link href="CSS/Menu.css" rel="stylesheet" type="text/css" />
    <link href="/SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script src="/SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
    </head>
    
    <body>
    <div id="Holder">
    <div id="Header"></div>
    <div id="NavBar">
        <nav>
            <ul>
                <li><a href="Login.php">Login</a></li>
                <li><a href="Register.php">Register</a></li>
                <li><a href="ForgotPassword.php">Forgot Password</a></li>
            </ul>
        </nav>
    </div>
    <div id="Content">
        <div id="PageHeading">
          <h1>Home Page </h1>
        </div>
        <div id="ContentLeft">
          <h2>This is a test page for a project in progress</h2>
          <p>&nbsp;</p>
          <h6>A work in progress.   </h6>
        </div>
        <div id="ContentRight">
          <form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
            <span id="sprytextfield1">
            <label for="LoginForm"></label>
            <span class="textfieldRequiredMsg">A value is required.</span></span>
            <table width="400" border="0" align="center">
              <tr>
                <td><h6><span id="sprytextfield2">
                  <label for="Username"></label>
                  Username:<br />
                  <br />
                  <input name="Username" type="text" class="StyleTxtField" id="Username" />
                  </span></h6>
                <span><span class="textfieldRequiredMsg">A value is required.</span></span></td>
                </tr>
              <tr>
                <td>&nbsp;</td>
                </tr>
              <tr>
                <td><h6><span id="sprytextfield3">
                  <label for="Password"></label>
                  Password:<br />
                  <br />
                  <input name="Password" type="text" class="StyleTxtField" id="Password" />
                  </span></h6>
                <span><span class="textfieldRequiredMsg">A value is required.</span></span></td>
                </tr>
              <tr>
                <td>&nbsp;</td>
                </tr>
              <tr>
                <td><input type="submit" name="LoginButton" id="LoginButton" value="Login" /></td>
                </tr>
              <tr>
                <td>&nbsp;</td>
                </tr>
              </table>
          </form>
        </div>
     </div>
    <div id="Footer"> </div>
    
    </div>
    <script type="text/javascript">
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
    var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
    var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
    </script>
    </body>
    </html>
    <?php
    mysql_free_result($Login);
    ?>
    
    
    无标题文件
    
    主页 这是正在进行的项目的测试页面

    正在进行的工作。
    您正在混合使用
    mysql
    mysqli
    函数。你不能那样做
    logincon.php
    需要使用
    mysqli\u connect
    ,而不是
    mysql\u pcconnect

    $logincon = mysqli_connect($hostname_logincon, $username_logincon, $password_logincon, $database_logincon) or trigger_error(mysqli_connect_error(),E_USER_ERROR); 
    
    在主脚本中,应该使用
    mysqli\u real\u escape\u string
    而不是
    mysql\u real\u escape\u string

    $theValue = myqsli_real_escape_string($logincon, $theValue);
    

    您必须使用
    mysqli_fetch_assoc
    mysqli_num_rows

    最后,我将mysql_*函数更改为mysqli_*函数。我现在的问题是脚本和Mysql数据库之间的问题。我将提出一个更相关的新问题


    再次感谢您的帮助。

    您是混合驱动程序<代码>Mysql
    !=<代码>mysqli。例如,
    $Login=mysqli\u query($logincon,$query\u Login)
    错误准确地说明了问题所在。使用
    include(
    )替换
    virtual(
    ),无论如何都不能使用
    virtual()
    (如错误消息所述,已禁用)。我尝试用include>Warning:include()[function.include]替换虚拟:打开“/Connections/logincon.php”以包含失败(include_path=”:/usr/lib/php:/usr/local/lib/php)在第2行的/home/a2575478/public_html/Login.php中,为了得到回复,添加了您所做的所有更改,但仍然存在错误。如果
    include
    失败,这将阻止脚本的其余部分正常工作。您需要弄清楚为什么它找不到脚本。可能问题是它应该是
    Logincon.php
    而不是
    logincon.php
    。现在我得到了一组新的错误。问题似乎在于logincon脚本或其信息的传递:
    注意:未定义变量:C:\xampp\htdocs\Login.php中的logincon,第11行警告:mysqli\u real\u escape\u string()参数1应为mysqli,在第11行的C:\xampp\htdocs\Login.php中为空
    您需要
    global$logincon;
    GetSQLValueString
    中,以便访问全局变量,或将
    $logincon
    作为参数传递给函数。
    $theValue = myqsli_real_escape_string($logincon, $theValue);