开发者

registration php file.

I have been trying to get this sign up php to work. I'm close, I guess. But there's a problem. The result is always a button that redirects to the homepage(You'll know what I'm talkin about when you read the code.) If you could find the problem please tell me.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" id="jmtoday" class=" no_js">
<head>
<link href='icon.jpg' rel='icon' type='image/jpg'/>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />开发者_运维问答;
<meta http-equiv="Content-language" content="en" />
<LINK REL=StyleSheet HREF="Mainstyles.css" TYPE="text/css"></link>
<Title>Sign up to JM Today</title>
</head>
<body>
<?php 
 $dbservertype='mysql';
 $servername='localhost';
 $dbusername='***';
 $dbpassword='***';
 $dbname='jmtdy';
 function connecttodb($servername,$dbname,$dbuser,$dbpassword)
 {
  global $link;
  $link=mysql_connect("$servername","$dbuser","$dbpassword");
  if(!$link){
   die("Could not connect to MySQL");
    }  
  mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
connecttodb($servername,$dbname,$dbusername,$dbpassword);
?>


<?php

 $username=mysql_real_escape_string($_POST['username']);
 $password=mysql_real_escape_string($_POST['password']);
 $password2=mysql_real_escape_string($_POST['password_confirmation']);
 $todo=mysql_real_escape_string($_POST['todo']);
 $email=mysql_real_escape_string($_POST['email']);
 $fname=mysql_real_escape_string($_POST['fname']);
 $lname=mysql_real_escape_string($_POST['lname']);



if(isset($todo) and $todo=="post"){

 $status = "OK";
 $msg="";
 }

if(!isset($username) OR strlen($username) <3){
 $msg=$msg."Username should be equal to or more than 3 characters long<BR/>";
 $status= "NOTOK";
 }     

if(mysql_num_rows(mysql_query("SELECT username FROM users WHERE username = '$username'")or die (mysql_error ()))){
$msg=$msg."Username already exists. Please try another one<BR/>";
$status= "NOTOK";}     


if ( strlen($password) < 3 ){
 $msg=$msg."Password must be more than 3 charactors long<BR/>";
 $status= "NOTOK";
 }     

if ( $password <> $password2 ){
 $msg=$msg."Passwords are not identical.<BR/>";
 $status= "NOTOK";
 }     


if($status="NOTOK"){
 echo "$msg<br/><input type='button' value='Retry' onClick='history.go(-1)'>";
}
 else {
if(mysql_query("insert into users(username,password,email,fname,lname) values('$username','$password','$email','$fname','$lname')")or die (mysql_error ())){
 echo "Welcome, You have successfully signed up";
 }
else { 
echo "Database Problem, please contact Site admin";
}

}
?>
</body>
</html>


You're missing an = on the line

if($status="NOTOK"){

It will assign the "NOTOK" to the $status and be boolean true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜