2015-08-18 69 views
-1

讓我開始說我已經閱讀了大約15個類似的線程在這裏和其他網站試圖解決我的問題發佈之前。我試圖用一些PHP和MySQL測試網站。一些信息:警告:mysqli_query()期望參數1是mysqli,給出的字符串

我建立了本地託管的站點,然後導出到000 webhost。爲了測試php和mysql的功能,這甚至是必要的嗎?我本地有一個mysql數據庫。這會造成問題嗎?

我有兩個問題。

  1. 在運行任何PHP腳本,我得到以下警告頁面:

警告:虛擬()已經被禁用在/home/a2575478/public_html/Login.php安全原因線2

警告:mysqli_query()預計參數1是mysqli的,在/home/a2575478/public_html/Login.php空給出上線37

警告:mysqli_error()預計參數1至被mysqli的,空在/home/a2575478/public_html/Login.php給出線37

我知道這些警告給mysql_ *函數關係被棄用,但我有麻煩固定棄用的功能

現在,當我嘗試訪問本地網頁時,我得到的是「網頁不可用」錯誤。是由於錯誤或只是試圖在本地運行PHP?

該網站可達here

讓我知道如果你需要任何更多的信息。

下面的代碼。

的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); 
?> 

Logincon.php,管理數據庫連接

<?php 
# FileName="Connection_php_mysql.htm" 
# Type="MYSQL" 
# HTTP="true" 
$hostname_logincon = "172.16.1.72:3306"; 
$database_logincon = "logindb"; 
$username_logincon = "root"; 
$password_logincon = "boombox"; 
$logincon = mysql_pconnect($hostname_logincon, $username_logincon, $password_logincon) or trigger_error(mysql_error(),E_USER_ERROR); 
?> 

預先感謝任何答覆

+0

您正在混合驅動程序。 'Mysql'' ='mysqli'。例如'$ Login = mysqli_query($ logincon,$ query_Login)'< - 'mysqli'然後...'$ row_Login = mysql_fetch_assoc($ Login);'你用'mysql_'然後同樣的驅動' $ totalRows_Login = mysql_num_rows($ Login);'然後回到'mysqli','mysqli_select_db($ database_logincon,$ logincon);' – chris85

+0

錯誤正好說明問題是什麼 –

+0

用'include('不管怎麼樣,我都會使用'virtual()'(禁用,因爲錯誤信息中提到) –

回答

2

你混合mysqlmysqli功能。你不能那樣做。 logincon.php需要使用mysqli_connect,而不是mysql_pconnect

$logincon = mysqli_connect($hostname_logincon, $username_logincon, $password_logincon, $database_logincon) or trigger_error(mysqli_connect_error(),E_USER_ERROR); 

,並在主腳本,你應該使用mysqli_real_escape_string,而不是mysql_real_escape_string

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

而且你必須使用mysqli_fetch_assocmysqli_num_rows

+0

感謝您的回覆,添加了所有更改,仍然有錯誤, – boombeatbob

+0

如果'include'失敗,則會阻止腳本的其餘部分正常工作。你需要弄清楚爲什麼它找不到腳本。也許問題是它應該是'Logincon.php'而不是'logincon.php'。 – Barmar

+0

現在我收到了一組新的錯誤。該問題似乎是與任一logincon腳本或它的信息的傳: '說明:未定義變量:用C logincon:\ XAMPP \ htdocs中\上線的login.php 11 警告:mysqli_real_escape_string()預計參數1爲mysqli,null在第11行的C:\ xampp \ htdocs \ Login.php中給出' – boombeatbob

0

最後我只是繞過將mysql_ *函數更改爲mysqli_ *函數。我的問題是現在腳本和我的Mysql數據庫之間。我會提出一個更相關的新問題。

再次感謝您的幫助。

相關問題