Variabls在(2)PHP脚本之间无法工作

时间:2017-04-02 15:17:53

标签: php mysql php-5.6 php4

我有(2)PHP脚本:一个用PHP 4.0编写,第二个用PHP 5.6编写(我的ISP升级了服务器,他们现在只运行PHP 5.6,所以我不得不将4.0脚本转换为5.6)

然而,当我使用PHP 4.0脚本时,一切都在ISP升级之前完美,但是当我使用PHP 5.6脚本(已转换)时,此脚本不会连接到mySQL服务器或返回任何值

我想知道初始变量是否有问题,或者从早期PHP 4.0脚本转换的第二个PHP 5.6脚本中可能缺少某些东西

由于

以下是(2)PHP脚本

PHP 4.0脚本

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

    }

    }

    ?>

这是PHP 5.6脚本

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

}

?>

1 个答案:

答案 0 :(得分:0)

解决了问题 - 只需在脚本中用$REMOTE_ADDR替换$_SERVER['REMOTE_ADDR']即可将PHP 4.0转换为PHP 5.6:)