mysql真正的转义字符串不返回任何内容 [英] mysql real escape string returns nothing

查看:54
本文介绍了mysql真正的转义字符串不返回任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释一下为什么这个简单的表格不起作用吗?

Can some one please explain why this simple form doesnt work?

问题是,当我使用 mysql_real_escape_string() 时,结果什么也没有,当我删除它时,它工作得很好,你能看看这里有什么问题吗?

The problem is that when I use mysql_real_escape_string() the result are nothing, when I remove it it works perfectly can you please see whats wrong here?

这是完整的简单代码,

<?php

// Loop the post fields
$postFields = array('username', 'password', 'checkSubmission');
$postArray = array();
foreach($postFields as $postVal){
    $postArray[$postVal] = mysql_real_escape_string($_POST[$postVal]);
}
print_r($postArray);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Signin</title>
<head>
</head>
<body><? echo $error;?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" id="signinForm">
    Username: <input type="text" name="username" value="" />
    Password: <input type="password" name="password" value="" />
    <input type="hidden" name="checkSubmission" value="1" />
    <input type="submit" name="Submit" value="Signin" />
</form>
</body>
</html>

当我使用 mysql_real_escape_string()

Array ( [username] => [password] => [checkSubmission] => )

这是没有mysql_real_escape_string()

Array ( [username] => thre[password] => werr[checkSubmission] => 1)

谢谢你的帮助

推荐答案

mysql_real_escape_string() 需要一个活动的数据库连接.

mysql_real_escape_string() requires an active database connection.

来自php手册:

使用mysql_real_escape_string()前需要连接MySQL否则会产生 E_WARNING 级别的错误,并且 FALSE 是回.如果未定义 link_identifier,则最后一个 MySQL 连接使用.

A MySQL connection is required before using mysql_real_escape_string() otherwise an error of level E_WARNING is generated, and FALSE is returned. If link_identifier isn't defined, the last MySQL connection is used.

http://php.net/manual/en/function.mysql-real-escape-string.php

这篇关于mysql真正的转义字符串不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆