12 Replies - 773 Views - Last Post: 20 December 2011 - 12:49 PM Rate Topic: -----

#1 theshowtekfan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 27-September 11

why is this registration system not working ?

Posted 19 December 2011 - 03:25 PM

when i try to make a registration system it displays that the user is already registered before even entering anything :(

whats wrong with this code ?
$username = (isset($_POST['username'])) ? $_POST['username'] : null;
$mail = (isset($_POST['mail'])) ? $_POST['mail'] : null;
$password = (isset($_POST['password'])) ? $_POST['password'] : null;
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$mail = mysql_real_escape_string($mail);
$password = SHA1($password, SALT);

if(isset($username,$password,$mail)) {
$query = "SELECT * FROM users WHERE username='".$username."' OR mail='".$mail."' ";
$fetch = mysql_query($query);
$rows = mysql_num_rows($fetch);

if (isset($username) AND $rows == 1) {
echo ("username or e-mail is already Registered.");
}
else {
$query = "INSERT into users (username,password,mail) VALUES ($username,$password,$mail)";
mysql_query($query);
echo("User Registrated sucessfully");
}
}


Is This A Good Question/Topic? 0
  • +

Replies To: why is this registration system not working ?

#2 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: why is this registration system not working ?

Posted 19 December 2011 - 03:46 PM

Nevermind. Previous answer:

Spoiler


What I don't understand is why you're doing the isset when setting the variables, when you're doing it again on line 9. Save yourself the trouble/confusion by $_POST variables :P

This post has been edited by EnvXOwner: 19 December 2011 - 03:50 PM

Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: why is this registration system not working ?

Posted 19 December 2011 - 03:46 PM

that shouldn’t be happening due to line #9. do a var_dump() on $_POST and your SQL query to check what variables you use.

hm, if the variables are empty (which are not caught by isset()), you would insert empty values, which will in turn give you 1 row when you test with empty values … just thinking.

Quote

You're doing $rows == 1. It should be something like $rows['username'] for that part.

why that, $rows is not a result row, it’s an integer returned from mysql_num_rows(). just because everyone calls his/her result set $row/$rows doesn’t mean that someone may use that name for something different.

This post has been edited by Dormilich: 19 December 2011 - 03:49 PM

Was This Post Helpful? 0
  • +
  • -

#4 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: why is this registration system not working ?

Posted 19 December 2011 - 03:53 PM

View PostDormilich, on 19 December 2011 - 05:46 PM, said:

Quote

You're doing $rows == 1. It should be something like $rows['username'] for that part.

why that, $rows is not a result row, its an integer returned from mysql_num_rows(). just because everyone calls his/her result set $row/$rows doesnt mean that someone may use that name for something different.


lol I caught it before you :P I did that by quickly scanning his code (the formatting looks awful here). That's why I edited my post saying nevermind, but I kept what I posted in a spoiler.
Was This Post Helpful? 0
  • +
  • -

#5 theshowtekfan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 27-September 11

Re: why is this registration system not working ?

Posted 19 December 2011 - 04:12 PM

yea okay ima do a vardump :P anyways i know that my formatting is awfull :( im using notepad++ and xampp what else should i use to get proper formatting ?
Was This Post Helpful? 0
  • +
  • -

#6 theshowtekfan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 27-September 11

Re: why is this registration system not working ?

Posted 19 December 2011 - 04:18 PM

ok this is the output of a var_dump();

string(0) "" string(20) "9^kK 2U` " string(0) "" 



and i found out that its not saying that the user is already registered but "user successfully registered" xD


anyone got a clue ?
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: why is this registration system not working ?

Posted 19 December 2011 - 04:18 PM

you should get indentation.

um, it would help to know, what variables you dumped there …

This post has been edited by Dormilich: 19 December 2011 - 04:19 PM

Was This Post Helpful? 0
  • +
  • -

#8 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: why is this registration system not working ?

Posted 19 December 2011 - 04:19 PM

You know, you could just press tab :P
Was This Post Helpful? 0
  • +
  • -

#9 theshowtekfan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 27-September 11

Re: why is this registration system not working ?

Posted 19 December 2011 - 05:58 PM

View PostDormilich, on 19 December 2011 - 04:18 PM, said:

you should get indentation.

um, it would help to know, what variables you dumped there


yea see for urself :)

here's the whole script

<?php
include('config.php');

$username = (isset($_POST['username'])) ? $_POST['username'] : null;
$mail = (isset($_POST['mail'])) ? $_POST['mail'] : null;
$password = (isset($_POST['password'])) ? $_POST['password'] : null;
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$mail = mysql_real_escape_string($mail);
$password = SHA1($password, SALT);

if(isset($username,$password,$mail)) {
$query = "SELECT * FROM users WHERE username='".$username."' OR mail='".$mail."' ";
$fetch = mysql_query($query);
$rows = mysql_num_rows($fetch);

if (isset($username) AND $rows == 1) {
echo ("username or e-mail is already Registered.");
}
else {
$query = "INSERT into users (username,password,mail) VALUES ($username,$password,$mail)";
mysql_query($query);
echo("User Registrated sucessfully");
var_dump($username);
var_dump($password);
var_dump($mail);
}
}

else {
echo ("Please fill in all fields before Registering.");
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>
<?php echo(booter_name);?> - Registration
</title>
</head>
<body>
<div id="main_frame">
<p>Desired username: <input type="text" maxlength="20" name="username" /></p><br>
<p>Desired password: <input type="password" maxlength="20" name="password" /></p><br>
<p>e-mail address: <input type="text" maxlength="20" name="mail" /></p><br>
<input type="submit" value="Register" />
</div>
</body>
</html>


Was This Post Helpful? 0
  • +
  • -

#10 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: why is this registration system not working ?

Posted 19 December 2011 - 06:38 PM

no wonder that didnt work. you need <form> tags to define a form.

and you are also aware that you echo your comments outside of the HTML document?

besides that, though you check whether the variables are set, you never check whether they are empty (or even valid).
Was This Post Helpful? 0
  • +
  • -

#11 theshowtekfan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 27-September 11

Re: why is this registration system not working ?

Posted 19 December 2011 - 11:33 PM

yea this is not a finished script.... thats why im working on coding it atm lol
Was This Post Helpful? 0
  • +
  • -

#12 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: why is this registration system not working ?

Posted 20 December 2011 - 03:18 AM

you need to get the HTML in order before you can proceed with PHP. because it will provide the input for the script.
Was This Post Helpful? 0
  • +
  • -

#13 theshowtekfan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 27-September 11

Re: why is this registration system not working ?

Posted 20 December 2011 - 12:49 PM

ik lol i have done this plenty of times before xD thats why i ws all upset and did not know why my "php" did not work :P i was not even thinking it could be my html xd
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1