mysql_real_escape_string() expects parameter 2 to be resource, object given in,该怎么解决
程序员文章站
2022-05-12 23:38:17
...
mysql_real_escape_string() expects parameter 2 to be resource, object given in
代码如下:
$page_title = 'Register ';
include("header.html"); #网页头部
?>
if(isset($_POST['submitted'])){
require_once("mysqli_connect.php");
$error=array(); #定义错误为数组
if (empty($_POST['first_name'])){
$error[]='you forgot to enter you first name';
}else{
$fn= mysql_real_escape_string(trim($_POST['first_name']),$dbc);
} #first name 条件语句
if (empty($_POST['last_name'])) {
$error[]='you forgot to enter you last name';
}else{
$ln= mysql_real_escape_string(trim($_POST['last_name']),$dbc);
} #last name 条件语句
if (empty($_POST['email'])){
$error[]='you forgot to enter you email';
}else{
$e= mysql_real_escape_string(trim($_POST['email']),$dbc);
} # email 条件语句
if (!empty($_POST['password1'])) {
if($_POST['password1']!=$_POST['password2']){
$error[]='your password did not match the confirmed password.';
}else{
$p= mysql_real_escape_string(trim($_POST['password1']),$dbc);
}
}else{
$error[]='you forgot to your password';
} # password 条件语句
if(empty($error)){
$q="INSERT INTO users (first_name, last_name, email, pass,registration_date) VALUES ('$fn','$ln','$e',SHA1('$p'),now())";
[email protected]_query ($dbc ,$q);
if($r){
echo '
}else{
echo "
}
mysqli_close($dbc);
include('footer.html');
exit();
}else{
echo"
foreach($error as $key =>$msg){
echo "the error at $key is $msg
";
}
echo"
} #错误显示
}
?>
代码如下:
$page_title = 'Register ';
include("header.html"); #网页头部
?>
if(isset($_POST['submitted'])){
require_once("mysqli_connect.php");
$error=array(); #定义错误为数组
if (empty($_POST['first_name'])){
$error[]='you forgot to enter you first name';
}else{
$fn= mysql_real_escape_string(trim($_POST['first_name']),$dbc);
} #first name 条件语句
if (empty($_POST['last_name'])) {
$error[]='you forgot to enter you last name';
}else{
$ln= mysql_real_escape_string(trim($_POST['last_name']),$dbc);
} #last name 条件语句
if (empty($_POST['email'])){
$error[]='you forgot to enter you email';
}else{
$e= mysql_real_escape_string(trim($_POST['email']),$dbc);
} # email 条件语句
if (!empty($_POST['password1'])) {
if($_POST['password1']!=$_POST['password2']){
$error[]='your password did not match the confirmed password.';
}else{
$p= mysql_real_escape_string(trim($_POST['password1']),$dbc);
}
}else{
$error[]='you forgot to your password';
} # password 条件语句
if(empty($error)){
$q="INSERT INTO users (first_name, last_name, email, pass,registration_date) VALUES ('$fn','$ln','$e',SHA1('$p'),now())";
[email protected]_query ($dbc ,$q);
if($r){
echo '
Thank you !
you are now registered.
';}else{
echo "
system error
you could not bi registered due to a system error . We apolagize for any inconvenience. mysqli_error:.mysqli_error($dbc).
Query:.$q.
}
mysqli_close($dbc);
include('footer.html');
exit();
}else{
echo"
error!
the following error occurrde :
" ;foreach($error as $key =>$msg){
echo "the error at $key is $msg
";
}
echo"
please try again
";} #错误显示
}
?>
Register
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
上一篇: 正则匹配file_get_contents,该如何处理
下一篇: JS匿名函数概念与用法分享
推荐阅读
-
mysql_real_escape_string() expects parameter 2 to be resource, object given in,该怎么解决
-
Warning: mysqli_error() expects exactly 1 parameter, 0 given in,该怎么解决
-
mysql_real_escape_string() expects parameter 2 to be resource, object given in,该怎么解决
-
Warning: mysqli_error() expects exactly 1 parameter, 0 given in,该怎么解决
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论