$ _GET或转义字符串是不可预测的。请解释?

时间:2013-04-25 22:26:42

标签: php

我只是将3个值传递给URL,而测试时我试图将它们回显到屏幕,但它只会回显每个值一次,即使我已将其设置为在各个点回显。一旦我逃脱了价值,它就不会让我回应它。这是为什么?

<?php
    session_start();
    if (isset($_SESSION['SESSION_C']) && ($_SESSION['SESSION_C']==true))
    {
        $getyear = $_GET["Year"];
        echo $getyear; (IT WILL ECHO AT THIS POINT)
        $getyear = mysql_real_escape_string($getyear);
        echo $getyear; (BUT WONT ECHO HERE)

        $getsite = $_GET["Site"];
        echo $getsite;
        $getsite = mysql_real_escape_string($getsite);
        echo $getsite;
        $getsite = str_replace(' ', '', $getsite);
        echo $getsite;

        $getdoc =  $_GET["Doc"];
        echo $getdoc;
        $getdoc = mysql_real_escape_string($getdoc);
        echo $getdoc;
    }   
    else 
    {
        echo "sessionerror";
    }
?>

1 个答案:

答案 0 :(得分:4)

mysql_real_escape_string()需要与mysql的开放连接。否则它将返回false。我猜var_dump($getdoc);会给你boolean(false)

您必须在该代码之前致电mysql_connect()