PDA

Click to See Complete Forum and Search --> : Inserting in register information please help


hacker786
Nov 15th, 2008, 01:51 AM
Here i am trying to insert a query for register the user in my site

any body can tell me dat wts the mistake is there :(


<?php
require("settings.php");
// Register information
if ($_POST['submit']!="") {
if($_POST['userid']!=""){
if ($_POST['username'] != "") {
if ($_POST['password'] != "") {
$userid = mysql_real_escap_string($_POST['userid']);
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
echo $userid;
echo $username;
echo $password;

$password = md5($password);//To stroe the password in md5
$sql =(" INSERT INTO 'users' (userID, username, password) VALUES('$userid','$username,'$password') ");
$query = mysql_query($sql);
echo "Register Successful";
}
else {
echo "Register Failed";
}
}
else {
echo "Please enter username";
}

}
else {
echo "please enter the password";
}
}


?>
<html>
<body>
<font color="#FF0000"></font>
<form action="register.php" method="post"> <br>
Userid:<input type="text" name="userid"><br>
Username:<input type="text" name="user"><br>
Password:<input type="password" name="pass"><br>
<input type="submit" name="Register" value="Register" ><br>
</body>
<html>

Please help me :(

visualAd
Nov 15th, 2008, 03:26 AM
I can see where your mistake is. But I am not going to tell you :p. How about posting the error message you receive and we can work on how find it yourself.

the182guy
Nov 15th, 2008, 07:14 AM
I think visualAd is trying to get you to learn how to debug your code, so I am not going to spoil that.

In that code there are 5 problems...

There is 1 fatal error, 2 errors in the SQL query and 2 problems with the logic.

If you are not getting an error message, then turn errors on using

error_reporting(E_ALL);


Or look in the access log for the error. When you do see the error, it should be obvious what the problem is.

When you have solved the fatal error which is halting the script. You can then look at solving the problems in the SQL query. If a MySQL query is not doing what it is supposed to, you can get the error message using the mysql_error() function like so:

echo mysql_error();


As for the logic, I don't know how anyone can easily read your logic with those if/else statements written like that, you should tab them properly.

The first logic problem I see is you are echoing "registration failed" if the password is blank. That's not an accurate error message, it should be like your others "please enter a password".

Secondly, you are echoing "Registration successful" after the query, regardless of the result.... that means if the query failed, your program will still tell the user it was successful. You can put an if statement around the $query variable to check if it failed or not, and then you can give the user that information e.g.

$query = mysql_query($sql);

if($query)
{
//success
}
else
{
//failed
}


Lastly, you have a lot of echo statements with error messages, why not put the message in a $msg variable and just use one echo statement at the end. This way you can add HTML markup to the echo without having to go through all of your echo statements.

dclamp
Nov 15th, 2008, 11:36 AM
I see the error as well. Also, i notice that you are echoing the userid, password, and username before they are sent to the db ( and before the password is md5'ed). My first guess is that you are attempting to debug. If not, then i would remove at least password and userid, and put something like "Thanks for registering USERNAME"

hacker786
Nov 15th, 2008, 01:37 PM
yeah thanx i got it:)

visualAd
Nov 16th, 2008, 04:13 AM
I think visualAd is trying to get you to learn how to debug your code, so I am not going to spoil that.


I wasn't trying to say that; I was trying to help him do it, but you spoiled that. :wave: