当前位置: 代码迷 >> PHP >> mysql_real_escape_string() expects parameter 2 to be resource, object given in,该怎么解决
  详细解决方案

mysql_real_escape_string() expects parameter 2 to be resource, object given in,该怎么解决

热度:762   发布时间:2012-05-22 18:18:54.0
mysql_real_escape_string() expects parameter 2 to be resource, object given in
代码如下:

<?php 
$page_title = 'Register ';
include("header.html"); #网页头部
?>

<?php 

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())";
$r=@mysqli_query ($dbc ,$q);
if($r){
echo ' <h1>Thank you !</h1>
<p> you are now registered. </p>';
}else{
echo "<h1> system error</h1>
<p> you could not bi registered due to a system error . We apolagize for any inconvenience. mysqli_error:.mysqli_error($dbc).<br />Query:.$q.</p>";
}
mysqli_close($dbc);
include('footer.html');
exit();
}else{
echo" <h1 > error!</h1><p> the following error occurrde :</p>" ;
foreach($error as $key =>$msg){
echo "the error at $key is $msg <br />";
}
echo"<p><h1>please try again </h1></p>";
} #错误显示
 
 
}
?>




<h1 align="center"> Register </h1>
<div style="width:750px; border-top:#000 solid 1px; margin:20px auto; ">
  <fieldset><legend>please do it </legend>
  <form action="register.php" method="post" > <!--表单内容-->
  <p>First_name: <input type="text" name="first_name" size="15" maxlength="20" value="<?php if(isset($_POST[first_name])) echo $_POST[first_name]?>" > </p>
  <p>Last_name: <input type="text" name="last_name" size="15" maxlength="40" value="<?php if(isset($_POST[last_name])) echo $_POST[last_name]?>" > </p>
  <p>Email Address: <input type="text" name="email" size="15" maxlength="60" value="<?php if(isset($_POST[email])) echo $_POST[email]?>" > </p>
  <p>Password: <input type="password" name="password1" size="20" maxlength="20" > </p>
  相关解决方案