$sql='INSERT INTO member (username,password,userpassq,userpassa,email,telephone,address) VALUES ('.$_POST['username'].','.$_POST['passwd'].','.$_POST['passdp'].','.$_POST['passda'].','.$_POST['email'].','.$_POST['tel'].','.$_POST['addr'].')'; 这个SQL语句应该通不过。在每个列的值边都要加单引号环绕 例如 $sql ="INSERT INTO member (username,password,userpassq,userpassa,email,telephone,address) VALUES ('{$_POST['username']}', '{$_POST['passwd']}' ....)";
} } //检查数据库中是否有同名的用户存在 $conn=@mysql_connect("localhost","root","") or die("failed to connect to database"); mysql_select_db("project",$conn); $sql="SELECT * FROM member WHERE usename='$username'"; $result=mysql_query($sql); if(mysql_fetch_object($result)){ mysql_close($conn); echo "用户名已经存在!";
} else{ //用户数据插入数据库 $sql="INSERT INTO member (memberid,username,password,userpassq,userpassa,email,telephone,address) VALUES (NULL,'".$_POST['username']."','".$_POST['passwd']."','".$_POST['passdp']."','".$_POST['passda']."','".$_POST['email']."','".$_POST['tel']."','".$_POST['addr']."')"; if(mysql_query($sql)){ $sql2="SELECT * FROM member WHERE username='$username'"; $result=mysql_query($sql2); $res=mysql_fetch_object($result); $id1=$res->memberid; session_register($id1); $reuturnpage="Location:membershow.php?$id='$id1'";
header($returnpage); ob_end_flush(); }else{
echo "注册失败!"; }
mysql_close($conn);
}
} 数据库出毛病了,大家看看是什么原因,报错如下: Notice: Undefined variable: username in D:\xampp\htdocs\web\register.php on line 115Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\web\register.php on line 117Notice: Undefined index: username in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined index: passwd in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined index: passdp in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined index: passda in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined index: email in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined index: tel in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined index: addr in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined variable: username in D:\xampp\htdocs\web\register.php on line 127Deprecated: Function session_register() is deprecated in D:\xampp\htdocs\web\register.php on line 131Notice: Undefined variable: id in D:\xampp\htdocs\web\register.php on line 132Notice: Undefined variable: returnpage in D:\xampp\htdocs\web\register.php on line 134
2、观看你的代码,没有看到发出 url 参数的地方
//检查用户的输入是否符合要求
$username=$_POST["username"];
$password=$_POST["passwd"];
$repasswd=$_POST["repasswd"];
$passwda=$_POST["passwdpa"];
$passwdq=$_POST["passwdq"];
if($username==""||$password=""||$repasswd=""||$passwdq=""||$passwda=""){
echo "必填项不能为空!";
}
这块不能执行!!!!!!!
VALUES ('.$_POST['username'].','.$_POST['passwd'].','.$_POST['passdp'].','.$_POST['passda'].','.$_POST['email'].','.$_POST['tel'].','.$_POST['addr'].')';
这个SQL语句应该通不过。在每个列的值边都要加单引号环绕
例如
$sql ="INSERT INTO member
(username,password,userpassq,userpassa,email,telephone,address)
VALUES
('{$_POST['username']}', '{$_POST['passwd']}' ....)";
http://database.51cto.com/art/201005/199957.htm
$msg=$_GET["message"];
if(!isset($msg)) $msg=$_POST["message"];
if($msg=='new'){
echo $str1;
exit();
}elseif($msg=='agree'){
echo $str2;
exit();
}elseif($msg=='reg'){
//检查用户的输入是否符合要求
$username=$_POST["username"];
$password=$_POST["passwd"];
$repasswd=$_POST["repasswd"];
$passwda=$_POST["passwdpa"];
$passwdq=$_POST["passwdq"];
if($username==""||$password=""||$repasswd=""||$passwdq=""||$passwda=""){
$message="必填项不能为空!";
}
if($password!=$repasswd){
$message="前后填的密码不一致!";
}
}
//检查数据库中是否有同名的用户存在
$conn=@mysql_connect("localhost","root","") or die("failed to connect to database");
mysql_select_db("project",$conn);
$sql="SELECT * FROM member WHERE usename='$username'";
$result=mysql_query($sql);
if(mysql_fetch_object($result)){
mysql_close($conn);
echo "用户名已经存在!";
}
else{
//用户数据插入数据库
$sql="INSERT INTO member (memberid,username,password,userpassq,userpassa,email,telephone,address)
VALUES (NULL,'".$_POST['username']."','".$_POST['passwd']."','".$_POST['passdp']."','".$_POST['passda']."','".$_POST['email']."','".$_POST['tel']."','".$_POST['addr']."')";
if(mysql_query($sql)){
$sql2="SELECT * FROM member WHERE username='$username'";
$result=mysql_query($sql2);
$res=mysql_fetch_object($result);
$id1=$res->memberid;
session_register($id1);
$reuturnpage="Location:membershow.php?$id='$id1'";
header($returnpage);
ob_end_flush();
}else{
echo "注册失败!";
}
mysql_close($conn);
}
}
数据库出毛病了,大家看看是什么原因,报错如下:
Notice: Undefined variable: username in D:\xampp\htdocs\web\register.php on line 115Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\web\register.php on line 117Notice: Undefined index: username in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined index: passwd in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined index: passdp in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined index: passda in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined index: email in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined index: tel in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined index: addr in D:\xampp\htdocs\web\register.php on line 125Notice: Undefined variable: username in D:\xampp\htdocs\web\register.php on line 127Deprecated: Function session_register() is deprecated in D:\xampp\htdocs\web\register.php on line 131Notice: Undefined variable: id in D:\xampp\htdocs\web\register.php on line 132Notice: Undefined variable: returnpage in D:\xampp\htdocs\web\register.php on line 134