Problem with Registration and log in script

Registration new members an log in on website

Page 1 of 1

4 Replies - 641 Views - Last Post: 29 November 2008 - 10:32 AM Rate Topic: -----

#1 stativa23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 27-November 08

Problem with Registration and log in script

Posted 27 November 2008 - 04:46 PM

 <?php
			   if(isset($_POST['submit'])){
			   $dbhost = "localhost";
			   $dbname = "name";
			   $dbuser = "username";
			   $dbpass = "pass";
				mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
				mysql_select_db($dbname) or die(mysql_error());
				$firstname=$_POST['firstname'];
				$lastname=$_POST['lastname'];
				$username=$_POST['username'];
				$password=md5($_POST['password']);   
				$email=$_POST['email'];
				 if($firstname==' ') { $error="First name required!";} 
				 if ($lastname==' ') { $error="Last name required!";}  
				 if ($username==' ') { $error="Username required!";}   
				 if ($password==' ') { $error="Password required!";} 
				 if ($email==' ') { $error="Email required!";}  
				 else
				  {
				   $checkuser = mysql_query("SELECT username FROM users WHERE username='$username'"); 
				   $username_exist = mysql_num_rows($checkuser);
				   if($username_exist =='1'){
				   $error= "I'm sorry but the username you specified has already been taken.  Please pick another					   one.";}
				   $query = "INSERT INTO users (firstname,lastname, username, password,email)
				   VALUES('$name', '$lastname', '$username', '$password','$email')";
				   mysql_query($query) or die(mysql_error());
				   $msg="You are now registered";
				 }
}
?>
<html>
<head><title>Registration</title></head>
<body>
<p></$msg/></p>
<form action="register.php" method="post">
<table border="0">
<tr><td>Firstname:</td>
<td><input type="text" name="firstname" value=""></td></tr>
<tr><td>Lastname:</td>
<td><input type="text" name="lastname" value=""></td></tr>
<tr><td>Username:</td>
<td><input type="text" name="username" value=""></td></tr>
<tr><td>Password:</td>
<td><input type="password" name="password" value=""></td></tr>
<tr><td>Email:</td>
<td><input type="email" name="email" value=""></td></tr>
<tr><td><input type="submit" name="submit" value="Submit"></td></tr>
</table>
</form>
</body>
</html>



I have problem when I put values to my register form always comes back "You are now registered" and when I am not entering values in some fields does not call for error that the field is required and to try again but it puts in my database as blanc fields.why is that?

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with Registration and log in script

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

Re: Problem with Registration and log in script

Posted 27 November 2008 - 05:31 PM

You are apparently testing to see if the value is a space, although there could be other character(s) in between ' '. If it is a space, then you error, if not, you continue on your merry way. I don't see it ever being a space.

I also noticed that you're hashing $_POST['password'], which is fine, but that can never be a space, and it's not predictable what it will be, so testing that is pointless. (md5(' ') produces: 7215ee9c7d9dc229d2921a40e899ec5f)
Was This Post Helpful? 0
  • +
  • -

#3 stativa23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 27-November 08

Re: Problem with Registration and log in script

Posted 28 November 2008 - 02:36 AM

View PostCTphpnwb, on 27 Nov, 2008 - 04:31 PM, said:

You are apparently testing to see if the value is a space, although there could be other character(s) in between ' '. If it is a space, then you error, if not, you continue on your merry way. I don't see it ever being a space.

I also noticed that you're hashing $_POST['password'], which is fine, but that can never be a space, and it's not predictable what it will be, so testing that is pointless. (md5(' ') produces: 7215ee9c7d9dc229d2921a40e899ec5f)




That is ok,I understand,but it does not make difference when I am not putting nothing in fields with firstname,lastname,username,always back to me You are now registered,but in the code I have stated that it shiuld return error if is nothing put in that fields,must be all fields full to go on You are now registered,and to check if the username is already in use,if it is,to return error,if is not in use to return ok...
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

Re: Problem with Registration and log in script

Posted 28 November 2008 - 07:56 PM

View Poststativa23, on 28 Nov, 2008 - 01:36 AM, said:

That is ok,I understand,but it does not make difference when I am not putting nothing...

No, it is not ok. Space does not equal null. The only way your code will set $error is if one of your variables is set to be a single space character, not zero characters, or two spaces, but exactly one space.
Was This Post Helpful? 0
  • +
  • -

#5 stativa23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 27-November 08

Re: Problem with Registration and log in script

Posted 29 November 2008 - 10:32 AM

View PostCTphpnwb, on 28 Nov, 2008 - 06:56 PM, said:

View Poststativa23, on 28 Nov, 2008 - 01:36 AM, said:

That is ok,I understand,but it does not make difference when I am not putting nothing...

No, it is not ok. Space does not equal null. The only way your code will set $error is if one of your variables is set to be a single space character, not zero characters, or two spaces, but exactly one space.

I fixed that,now it is ok :) Thanks a lot CTphpnwb,you pointed to me to realize
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1