-1

Let me start by saying that I've read about 15 similar threads on here and other sites trying to fix my problem before posting.

Im testing a site with some php and mysql. Some info:

I built the site hosted locally, then exported to 000 webhost. Is that even necessary in order to test php and mysql functions? I have a mysql database locally. Would this be causing the problems?

I have two problems.

  1. On pages that run any php scripts i get the following warnings:

Warning: virtual() has been disabled for security reasons in /home/a2575478/public_html/Login.php on line 2

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/a2575478/public_html/Login.php on line 37

Warning: mysqli_error() expects parameter 1 to be mysqli, null given in /home/a2575478/public_html/Login.php on line 37

I know these warnings are related to mysql_* functions being deprecated but am having trouble fixing the deprecated functions

2.

Now, when i try to access the web pages locally, all i get is a "Webpage is not available" error. Is that due to the errors or just trying to run php locally?

The site is reachable here

Let me know if you need any more information.

Code below.

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, manages the database connection

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

Thanks in advance for any replies

Mukamik
  • 1
  • 1
  • 2
  • 2
  • You are mixing drivers. `Mysql_` != `mysqli`. For example `$Login = mysqli_query($logincon,$query_Login)` <-- `mysqli` then ... `$row_Login = mysql_fetch_assoc($Login);` your with `mysql_`then same driver again, ` $totalRows_Login = mysql_num_rows($Login);` then back to `mysqli`,`mysqli_select_db($database_logincon, $logincon);` – chris85 Aug 18 '15 at 19:30
  • The error says precisely what the problem is – Maytham Fahmi Aug 18 '15 at 19:30
  • Replace `virtual(` with `include(`, you can't use `virtual()` anyway (disabled, as the error message says). – Charlotte Dunois Aug 18 '15 at 19:48
  • I tried replacing virtual with include >Warning: include() [function.include]: Failed opening '/Connections/logincon.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/a2575478/public_html/Login.php on line 2 – Mukamik Aug 18 '15 at 20:31

2 Answers2

2

You're mixing mysql and mysqli functions. You can't do that. logincon.php needs to use mysqli_connect, not mysql_pconnect.

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

And in the main script you should use mysqli_real_escape_string instead of mysql_real_escape_string.

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

And you have to use mysqli_fetch_assoc and mysqli_num_rows.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thanks for the reply, added all the changes you gave, still having the errors though. – Mukamik Aug 18 '15 at 20:36
  • If `include` is failing, that will prevent the rest of the script from working correctly. You need to figure out why it's not finding the script. Maybe the problem is that it should be `Logincon.php` instead of `logincon.php`. – Barmar Aug 18 '15 at 20:39
  • Now I'm getting a new set of errors. The problem does seem to be with either the logincon script or the passing of its information: `Notice: Undefined variable: logincon in C:\xampp\htdocs\Login.php on line 11 Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\Login.php on line 11` – Mukamik Aug 19 '15 at 02:02
  • You need `global $logincon;` in `GetSQLValueString` so you can access the global variable, or pass `$logincon` as a parameter to the function. – Barmar Aug 19 '15 at 18:16
0

In the end I just went around changing mysql_* functions to mysqli_* functions. My problem is now between the scripts and my Mysql database. I'll make a new question that's more relevant.

Thanks again for all the help.

Mukamik
  • 1
  • 1
  • 2
  • 2