Jump to content

Registration Problem


MadDawgX

Recommended Posts

Hey, I've got a problem with my code that I can't figure out. The following code is at the top of my php page before the <html> line.

[code]<?php
$error = '';

/* make database connection */
$db = mysql_connect ('*********','********','********');
mysql_select_db ('********',$db);

if (isset($_POST["username"])) {
// Get Values
$username = $_POST["username"];
$password = $_POST["password"];
$password2 = $_POST["password2"];
$email = $_POST["email"];
$email2 = $_POST["email2"];
$location = $_POST["location"];
$bd = $_POST["bd"];
$bm = $_POST["bm"];
$by = $_POST["by"];
$gender = $_POST["gender"];
$homepage = $_POST["homepage"];

// Make sure fields are filled out
if($username=NULL|$password=NULL|$password2=NULL|$email=NULL|$email2=NULL) {
$error = 'A required field was left blank.';
} else {
// Passwords Match
if($password!=$password2) {
$error = "Passwords don't Match.";
} else {
// Emails Match
if ($email!=$email2) {
$error = "Email's don't Match.";
} else {
// Has Username Been Used
$checkuser = mysql_query("SELECT name FROM user WHERE name='$username'");
$user_exists = mysql_num_rows($checkuser);
if($user_exists>0) {
$error = "Username already in use.";
} else {
$checkemail = mysql_query("SELECT email FROM user WHERE email='$email'");
$email_exists = mysql_num_rows($checkemail);
if ($email_exists>0) {
$error = "A user is already registered with that email.";
} else {
$password = md5($password);
$query = "INSERT INTO user (name, pass, email, loc, gender, home, bd, bm, by) VALUES('$username','$password','$email'," .    "'$location', '$gender', '$homepage', '$bd', '$bm', '$by' )";
mysql_query($query) or die(mysql_error());
$registered = 1;
}
}
}
?>[/code]

The error I get is "Parse error: parse error, unexpected $ in ****** on line 451"

Line 451 is the </html> (end of document)

- Thanx
Link to comment
Share on other sites

Don't know why it pasted like that, but in the actual thing it's like this:

[code]$query = "INSERT INTO user (name, pass, email, loc, gender, home, bd, bm, by) VALUES('$username','$password','$email'," .   
"'$location', '$gender', '$homepage', '$bd', '$bm', '$by' )";[/code]

I also changed | to ||, but no luck.
Link to comment
Share on other sites

[quote author=hackerkts link=topic=103356.msg411495#msg411495 date=1155005271]
Your elseif is wrong, its in a mess..
Also, [b]=[/b] and [b]==[/b] is totally different.

[code]if($username==NULL||$password==NULL||$password2==NULL||$email==NULL||$email2==NULL) {[/code]
[/quote]

Yeah I changed that line with the == and || and still got the same error.

As for the else/elseif I'll try that now.

EDIT: Still no luck. This is what I have now, anything missing?

[code]<?php
$error = "";
$registered = 0;

/* make database connection */
$db = mysql_connect ('*********','********','********');
mysql_select_db ('********',$db);

if (isset($_POST["username"])) {
// Get Values
$username = $_POST["username"];
$password = $_POST["password"];
$password2 = $_POST["password2"];
$email = $_POST["email"];
$email2 = $_POST["email2"];
$location = $_POST["location"];
$bd = $_POST["bd"];
$bm = $_POST["bm"];
$by = $_POST["by"];
$gender = $_POST["gender"];
$homepage = $_POST["homepage"];

// Make sure fields are filled out
if($username==NULL||$password==NULL||$password2==NULL||$email==NULL||$email2==NULL) {
$error = 'A required field was left blank.';
// Passwords Match
} elseif($password!=$password2) {
$error = "Passwords don't Match.";
// Emails Match
} elseif ($email!=$email2) {
$error = "Email's don't Match.";
// Emails Match
} else {
$checkuser = mysql_query("SELECT name FROM user WHERE name='$username'");
$user_exists = mysql_num_rows($checkuser);
if($user_exists>0) {
$error = "Username already in use.";
} else {
$checkemail = mysql_query("SELECT email FROM user WHERE email='$email'");
$email_exists = mysql_num_rows($checkemail);
if ($email_exists>0) {
$error = "A user is already registered with that email.";
} else {
$password = md5($password);
$query = "INSERT INTO user (name, pass, email, loc, gender, home, bd, bm, by) VALUES('$username','$password','$email'," .   "'$location', '$gender', '$homepage', '$bd', '$bm', '$by' )";
mysql_query($query) or die(mysql_error());
$registered = 1;
}
}
}
?>[/code]
Link to comment
Share on other sites

I've got another problem, felt I could just post it here.

I'm getting a MySQL error:

[code]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by) VALUES('a', '0cc175b9c0f1b6a831c399e269772661', 'a', '', 'Undisclosed', '', ' at line 1[/code]

With this code:

[code] $query = "INSERT INTO user (name, pass, email, loc, gender, home, bd, bm, by) VALUES('$username', '$password', '$email', '$location', '$gender', '$homepage', '$bd', '$bm', '$by' )";
mysql_query($query) or die(mysql_error());[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.