MadDawgX Posted August 8, 2006 Share Posted August 8, 2006 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 Quote Link to comment Share on other sites More sharing options...
hackerkts Posted August 8, 2006 Share Posted August 8, 2006 Take a look at[code]$query = "INSERT INTO user (name, pass, email, loc, gender, home, bd, bm, by) VALUES('$username','$password','$email'," .[/code]Btw.. Change | to || Quote Link to comment Share on other sites More sharing options...
MadDawgX Posted August 8, 2006 Author Share Posted August 8, 2006 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. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted August 8, 2006 Share Posted August 8, 2006 Hmm.. Use elseif..[b]Edit[/b]:Change = to == Quote Link to comment Share on other sites More sharing options...
MadDawgX Posted August 8, 2006 Author Share Posted August 8, 2006 Would that really make a difference though? Quote Link to comment Share on other sites More sharing options...
hackerkts Posted August 8, 2006 Share Posted August 8, 2006 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 Link to comment Share on other sites More sharing options...
MadDawgX Posted August 8, 2006 Author Share Posted August 8, 2006 [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] Quote Link to comment Share on other sites More sharing options...
hackerkts Posted August 8, 2006 Share Posted August 8, 2006 You short of one more [b]}[/b][b]Edit[/b]:Make your life easier :P[code]else { $checkemail = mysql_query("SELECT email FROM user WHERE email='$email'"); $email_exists = mysql_num_rows($checkemail);[/code] Quote Link to comment Share on other sites More sharing options...
MadDawgX Posted August 8, 2006 Author Share Posted August 8, 2006 Wow. All that and it was a simple }. Thanx for your help. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted August 8, 2006 Share Posted August 8, 2006 Your welcome, if you have any more problems feel free to ask. :)Cheers~ Quote Link to comment Share on other sites More sharing options...
MadDawgX Posted August 8, 2006 Author Share Posted August 8, 2006 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] Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 8, 2006 Share Posted August 8, 2006 Try changing the field name from by to something like author. Then post if you are still getting the error.You can still use $by but change the field in the database to something else Quote Link to comment Share on other sites More sharing options...
MadDawgX Posted August 8, 2006 Author Share Posted August 8, 2006 Okay, thanx. That worked. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.