zeeshan Posted March 11, 2008 Share Posted March 11, 2008 here is the script which just created i still have problem after a long time of hard work too <?session_start(); include("database.php");function usernameTaken($username){ global $conn; if(!get_magic_quotes_gpc()){ $username = addslashes($username); } $q = "select username from info = '$username'"; $result = mysql_query($q,$conn); return (mysql_numrows($result) > 0);}function addNewUser($Username, $Password,$Confirm password,$Email,$Confirm email,$Trainer's title){ global $conn; $q = "INSERT INTO users VALUES ('$Username', '$Password','$Confirm_password','$Email','$Confirm_emil','$Trainer's_title')"; return mysql_query($q,$conn);}function displayStatus(){ $uname = $_SESSION['registrationusername']; if($_SESSION['registrationresult']){?><h1>Registered!</h1><p>Thank you <b><? echo $Username; ?></b>, your information has been added to the database, you may now <a href="register.php" title="Login">log in</a>.</p><? } else{?><h1>Registration Failed</h1><p>We're sorry, but an error has occurred and your registration for the username <b><? echo $Username; ?></b>, could not be completed.<br>Please try again at a later time.</p><? } unset($_SESSION['registrationusername']); unset($_SESSION['registered']); unset($_SESSION['registrationresult']);}if(isset($_SESSION['registered'])){?><html><title>Registration Page</title><body><? displayStatus(); ?></body></html><? return;}if(isset($_POST['subjoin'])){ if(!$_POST['user'] || !$_POST['pass']){ die('You didn\'t fill in a required field.'); } $_POST['user'] = trim($_POST['user']); if(strlen($_POST['user']) > 30){ die("Sorry, the username is longer than 30 characters, please shorten it."); } if(usernameTaken($_POST['user'])){ $use = $_POST['user']; die("Sorry, the username: <strong>$Username</strong> is already taken, please pick another one."); } $md5pass = md5($_POST['pass']); $_SESSION['registrationusername'] = $_POST['user']; $_SESSION['regresult'] = addNewUser($_POST['user'], $md5pass); $_SESSION['registered'] = true; echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">"; return;}else{?><html><title>Registration Page</title><body><h1>Register</h1><form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"><table align="left" border="0" cellspacing="0" cellpadding="3"><tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr><tr><td>Password:</td><td><input type="password" name="Confirm password" maxlength="30"></td></tr><tr><td>Confirm password:</td><td><input type="password" name="Confirm password" maxlength="30"></td></tr><tr><td>Email:</td><td><input type="text" name="Email" maxlength="30"></td></tr><tr><td>Confirm email:</td><td><input type="text" name="Confirm email" maxlength="30"></td></tr><tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr></table></form></body></html><?}?> Link to comment Share on other sites More sharing options...
justsomeguy Posted March 11, 2008 Share Posted March 11, 2008 There are quite a few problems with this.The SQL query in your usernameTaken function is not a valid SQL query. There's no table name or field name, I'm not even sure what is missing but it's missing at least one thing.The parameter list for addNewUser has several problems, you can't have spaces in variable names and a single quote in PHP starts a string, you can't have punctuation inside variable names. The SQL query in that function has the same problem.It looks like you're trying to use $_SESSION['regresult'] and $_SESSION['registrationresult'] as the same thing, you need to be consistent.It would be better to use the long PHP tags, some servers have the short tags disabled for compatibility with XHTML.In the displayStatus function you're trying to use $uname and $Username for the same thing, again, you need to be consistent. Also in the same function you are unsetting the session variables no matter what, I'm not sure if that's what you meant to do or not.Also, in a couple if statements you have a return statement. You don't return from an if, those returns should be calls to the exit() function instead.In the if statement that checks if the form was submitted you're again using 2 variables for the same thing. You need to focus on using the same variable names.When you call the addNewUser function you're only sending it 2 parameters, but it requires 6.Also, it's better to use $_SERVER then $HTTP_SERVER_VARS, $HTTP_SERVER_VARS is old and is no longer used. i still have problem after a long time of hard work tooIt looks more like you're pasting a bunch of stuff together without learning how it works first. You need to read the PHP manual that I linked to in another post. It will help you. Link to comment Share on other sites More sharing options...
zeeshan Posted March 12, 2008 Author Share Posted March 12, 2008 i have learnt from w3schools.com and now i should learn from the manual too Link to comment Share on other sites More sharing options...
Synook Posted March 12, 2008 Share Posted March 12, 2008 The manual is for reference - so if you suddenly think, for example, "why am I not getting anything from the $_SERVER superglobal?", or "What parameters did escape() take again?", you would search on the PHP manual. Link to comment Share on other sites More sharing options...
zeeshan Posted March 12, 2008 Author Share Posted March 12, 2008 ok thats cool and else where can i learn php on Link to comment Share on other sites More sharing options...
Synook Posted March 12, 2008 Share Posted March 12, 2008 Books! PHP for Dummies is good. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.