|
-
Nov 15th, 2008, 02:51 AM
#1
Thread Starter
Lively Member
Inserting in register information please help
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 Code:
<?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
-
Nov 15th, 2008, 04:26 AM
#2
Re: Inserting in register information please help
I can see where your mistake is. But I am not going to tell you . How about posting the error message you receive and we can work on how find it yourself.
-
Nov 15th, 2008, 08:14 AM
#3
Re: Inserting in register information please help
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
PHP Code:
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:
PHP Code:
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.
PHP Code:
$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.
-
Nov 15th, 2008, 12:36 PM
#4
Re: Inserting in register information please help
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"
Last edited by dclamp; Nov 15th, 2008 at 12:50 PM.
My usual boring signature: Something
-
Nov 15th, 2008, 02:37 PM
#5
Thread Starter
Lively Member
Re: Inserting in register information please help
yeah thanx i got it
-
Nov 16th, 2008, 05:13 AM
#6
Re: Inserting in register information please help
 Originally Posted by the182guy
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|