PDA

View Full Version : User Registration...



alexjewell
12-31-2006, 12:42 AM
I'm working on a user registration using PHP and MySQL. I have a database set up, called "ajuser" and a table set up called "userlogin".

What's odd is that it goes through without any errors, but just doesn't work. So, here's the code:



$name = $_POST['name'];
$user = $_POST['user'];
$pass = $_POST['pass'];
$pass_conf = $_POST['pass_conf'];
$email = $_POST['email'];
$ip = $_SERVER["REMOTE_ADDR"];

if( $name == false || $user == false || $pass == false || $pass_conf == false || $email == false) {
echo '<p>Please Fill In All Fields</p>';}

else if ( $pass != $pass_conf) {
echo '<p>Password and Confirm Password fields do not match. Fields ARE case sensitive!</p>';}

else {
$connection = mysql_connect($host, $dbuser, $dbpass);
$db = mysql_select_db($dbname, $connection);
$sql = "INSERT INTO userlogin (name,username,password,email,ip) VALUES ($name, $user, $pass, $email, $ip)";
$result = mysql_query($sql);
echo '<p>Thanks for registering. You may now login.</p>';}


Now, it shows the "Thanks for Registering" message...but when I look at the table, it's empty!

What's wrong?

alexjewell
01-01-2007, 05:48 AM
Alright, I see no one's looking at this question? Well, I updated the code:



$name = $_POST['name'];
$user = $_POST['user'];
$pass = $_POST['pass'];
$pass_conf = $_POST['pass_conf'];
$email = $_POST['email'];
$ip = $_SERVER["REMOTE_ADDR"];

if( $name == false || $user == false || $pass == false || $pass_conf == false || $email == false) {
echo '<p>Please Fill In All Fields</p>';}

else if ( $pass != $pass_conf) {
echo '<p>Password and Confirm Password fields do not match. Fields ARE case sensitive!</p>';}

else {
$connection = mysql_connect($host, $dbuser, $dbpass);
$db = mysql_select_db($dbname, $connection);
$sql = "INSERT INTO `userlogin` ('name','username','password','email','ip') VALUES ($name, $user, $pass, $email, $ip)";
mysql_query($sql);
echo '<p>Thanks for registering. You may now login.</p>';}

Titan85
01-02-2007, 12:55 AM
The only thing I can see is that your line:
$sql = "INSERT INTO `userlogin` ('name','username','password','email','ip') VALUES ($name, $user, $pass, $email, $ip)";Should be:
$sql = "INSERT INTO `userlogin` ('name','username','password','email','ip') VALUES ('$name', '$user', '$pass', '$email', '$ip')"; Note the ' ' around the values. I think that will make it work, hope it helps

costas
01-02-2007, 09:01 AM
In my queries I use that format and it works:


$sql = "insert into userlogin values('$name', '$user', '$pass', '$email', '$ip')";

Try it! And I hope it works!!
Have a Happy New Year!

alexjewell
01-02-2007, 01:29 PM
Costas - did you leave the double quotes on the end off on purpose? Or should it be:



$sql = "insert into userlogin values('$name', '$user', '$pass', '$email', '$ip')";


?

costas
01-02-2007, 02:07 PM
No, the quotes must be there (I corrected it)! Without them the query wont be only the "insert into userlogin values('$name', '$user', '$pass', '$email', '$ip')" but also all the rest code until the next "!!