phpmysqlphp-5.6php4

Variabls not working between (2) PHP Scripts


I have (2) PHP scripts: one written in PHP 4.0 and the second one written in PHP 5.6 (my ISP upgraded the servers and they only run PHP 5.6 now so I had to convert the 4.0 script to 5.6)

However when I use the PHP 4.0 script everything worked perfect prior to the ISP upgrade but when I use the PHP 5.6 script (which was converted), this script does not connect to the mySQL server or return any values

I am wondering if perhaps something is either wrong with the initial variables or perhaps something is missing in the second PHP 5.6 script that was converted from the earlier PHP 4.0 Script

Thanks

Here are the (2) PHP Scripts

The PHP 4.0 Script

    <?php

    $userdb="var1";

    $pass="var2";

    $database="var3";

    mysql_connect("sql.servername.com",$userdb,$pass);


    @mysql_select_db($database) or die ( header('location: status4.htm') );


    $match = "select id from USER_ACCOUNTS where username = '$username' and password = '$password'";

    $qry = mysql_query($match)
    or die ( header('location: status.htm?status=9') );
    $num_rows = mysql_num_rows($qry); 

    // Valid Username and Password

    if ($num_rows > 0) { 

    $qry = "SELECT * FROM USER_ACCOUNTS WHERE username like '%" . $username . "%'";
    $res = mysql_query($qry);
    $output='';


    while($row = mysql_fetch_assoc($res)){

    // loop through all returned results

    $output .= '&viewUsername=' . $row['viewUsername'] . '&viewPassword=' . $row['viewPassword'] . '&username=' . $row['username'] . 

    '&password=' . $row['password'] . '&name=' . $row['name'] . '&title=' . $row['title'] . '&email=' . $row['email'] . '&admin=' . 

    $row['admin'] . '&file=' . $row['file'] . '&file2=' . $row['file2'] . '&file3=' . $row['file3'] . '&file4=' . $row['file4'];

    echo "&status=1";

    echo $output;

    }

    }

    ?>

And here is the PHP 5.6 Script

 <?php

//error_reporting(1);
//ini_set('display_errors', '1');

// mysql connection
$db_host = 'sql.servername.com';
$db_user = 'var1';
$db_pass = 'var2';
$db_name = 'var3';

$dbh = new PDO('mysql:host='.$db_host.';dbname='.$db_name.';charset=utf8', $db_user, $db_pass);

// submit form
if (isset($_POST['submit']))
{

    $username = $_POST['username'];
    $password = $_POST['password'];

    $stmt = $dbh->prepare("SELECT * FROM USER_ACCOUNTS WHERE username = :username AND password = :password");
    $stmt->bindParam(':username', $username);
    $stmt->bindParam(':password', $password);
    $stmt->execute();
    $number_of_rows = $stmt->fetchColumn();

    // Valid Username and Password
    if ($number_of_rows > 0)
    {
        $row = $stmt->fetchAll(); 

        $output = '';

        while($row)
        {
            // loop through all returned results
            $output .= '&viewUsername=' . $row['viewUsername'] . '&viewPassword=' . $row['viewPassword'] . '&username=' . $row

['username'] . '&password=' . $row['password'] . '&name=' . $row['name'] . '&title=' . $row['title'] . '&email=' . $row['email'] . 

'&admin=' . $row['admin'] . '&file=' . $row['file'] . '&file2=' . $row['file2'] . '&file3=' . $row['file3'] . '&file4=' . $row

['file4'];
            echo "&status=1";
            echo $output;
        }
    }

}

?>

Solution

  • Solved it - simply replace $REMOTE_ADDR with $_SERVER['REMOTE_ADDR'] in the script to convert from PHP 4.0 to PHP 5.6 :)