2010-03-28 65 views
0

我的查询:所有符号后“和”剥离

mysql::getInstance()->update('requests', array('response' => mysql_real_escape_string($_POST['status'])), array('secret' => $_POST['secret'])); ?> 

如果我魔杖与“&”符号,所有符号添加字符串后“&”剥离。 !

举例: 字符串:“№;%:? ()_ + @#$%^ &()_ +

数据库

我只看到:!” №; %:?*()_ +!@#$%^

如何解决这个问题?

更新功能,如果有人需要:

function update($table, $updateList, $whereConditions) 
{ 
    $updateQuery = ''; 
    foreach ($updateList as $key => $newValue) { 
     if (!is_numeric($newValue)) { 
      $newValue = "'" . $newValue . "'"; 
     } 
     if (strlen($updateQuery) == 0) { 
      $updateQuery .= '`' . $key . '` = ' . $newValue; 
     } else { 
      $updateQuery .= ', `' . $key . '` = ' . $newValue; 
     } 
    } 
    return $this->query('UPDATE ' . $table . ' SET ' . $updateQuery . $this->buildWhereClause($whereConditions)); 
} 

UPD: 回声的MySQL ::的getInstance() - > getLastSQL()说:

UPDATE requests SET `response` = '!\"№;%:?*()_ [email protected]#$%^' WHERE `secret` = '52a4ab5f7f3e8491e60b71db7d775ee2' 

左右,随着MySQL的功能更新问题类?

Slaks,我需要使用str_replace函数( '&', '%28',$查询); ?

+1

如果你回显'$ _POST ['status']',你看到了什么? – SLaks 2010-03-28 01:39:48

+1

作为旁注:您的更新例程应确保转义newValue字符串,而不是调用方。 – hurikhan77 2010-03-28 01:47:41

+0

hurikhan77,请问我可以看看示例代码吗? – user300413 2010-03-28 02:02:20

回答

3

您可能会在查询字符串中传入原始&字符,这会导致&被PHP解析为第二个参数。 (在进入变量之前)

您需要将&转义为%26

编辑:在将它发送到服务器之前,您需要将其转义。 (当你发出HTTP请求时)