【问题标题】:how pg_escape_string return the value in array [closed]pg_escape_string 如何返回数组中的值 [关闭]
【发布时间】:2011-05-19 09:00:50
【问题描述】:

我的数组没有像 D'Souza 那样返回 ' 值

$query= "select vmname,guid,hostid,guestosname from vmobjects";

    AddLog("infrastructure.php","Query: ".$query,ERR_DEBUG_LOW);
    $result = pg_query($conn,$query);
    $no_records=pg_num_rows($result);
    $j=$no_records;
    $i=0;
    while($row = pg_fetch_array($result))
    {
        if($row[3]=="")
        {
            $vmobj_Array[$i]=$row[0].'***'.$row[1].'***'.$row[2];
        }
        else
        {

            $vmobj_Array[$i]=$row[0].'***'.$row[1].'***'.$row[2];
        }
        $i++;
    }

这是我在其他页面上的 pg_escape_string

$username_escaped = pg_escape_string($username);
    $password_escaped = pg_escape_string($password);
    $name_escaped = pg_escape_string($name);

        $query = "insert into vmobjects (guid,ipaddress,username,password,hostid,vmname,guestostype) values('".$guid."','".$ip."','".$username_escaped."','".$password_escaped."','".$hostid."','".$name_escaped."','".strtolower($os)."')";

【问题讨论】:

    标签: php arrays escaping arraylist


    【解决方案1】:

    当您说“不返回”时,您是指在您使用任何管理数据库的方式查询数据库时,还是指在网页中显示结果时?

    我会认为你的意思是后者,在这种情况下,我猜现在问题出现了,因为你显示它的表单使用单引号 value =''。您可以通过查看相关页面的 html 源代码来证明是否是这种情况。

    您应该使用 htmlentities() 或该系列的 html 转义机制来转义数据以在 html 中显示(并保护您的用户免受可能的 xss 攻击)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多