Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-21-2011, 10:13 PM   PM User | #1
Skylear
New Coder

 
Join Date: Jul 2011
Location: Kansas
Posts: 15
Thanks: 3
Thanked 0 Times in 0 Posts
Skylear is an unknown quantity at this point
Question Parse Error on Closing PHP Line??

I'm coding a registration form and I'm a newbie. I did all the basic stuff and closed my PHP, but it still says there's a parse error on the line my PHP closes.

PHP Code:
<?php
//This is just starting a session.
session_start();

//Database info.
$dbhost "localhost";
$dbname "sky";
$dbuser "sky";
$dbpass "105000";

//Either this thing connects, or it's gunna die.
$con mysql_connect($dbhost$dbuser$dbpass) or die("MySQL Error: " mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " mysql_error());

//First, we store the information gathered from the form in variables.
$username=$_POST['username'];
$pass=$_POST['password'];
$email=$_POST['email'];

$password=md5($pass); //Here, we use the md5() function to encrypt the user's password.
$confirm_password=$_POST['confirmpass']; //NOW we store the confirmation password.
 

$queryuser=mysql>("SELECT * FROM people WHERE username='$username'");
$checkuser=mysql_num_rows($queryuser); //This query will check to see if the inserted username is already taken or not.

$queryemail=mysql>("SELECT * FROM people WHERE email='$email'");
$checkemail=mysql_num_rows($queryemail); //This does the same as the first query, but instead checks for the inserted email address.

if($checkuser != 0)
{ echo 
"Sorry, ".$username." is already taken."; } //If the username is already taken, it will display a message.
else {
    if(
$pass != $confirm_password//Checks to see if the two passwords macth or not.
    
{ echo "Your passwords don't match."; }
else {
    if(
$checkemail != 0//if the email is already taken, it will display a message.
    
{ echo "Sorry, ".$email." is already registered.."; }
else {
    if(
$username=""//Checks to see if the user actually inserted a username.
    
{ echo "Please provide a username."; } 
else {
    if(
$password=""//Checks to see if the user actually inserted a password.
    
{ echo "Please provide a password."; } 
else {
    if(
$email=""//Checks to see if the user actually inserted an email address.
    
{ echo "Please provide an email address."; }
else {
$insert_user mysql>("INSERT INTO login (id, username, password, email, date, banned, level) VALUES(NULL, '$username', '$password', '$email', NULL, 'No', 'Member')"); }; //Inserts the data if everything checks out okay.
 
if($insert_user//Did the information successfully insert into the database?
{ echo "You successfully registered!"; } //If yes, then congrats!
else
{ echo 
"Gosh dang it, there was an error in registration. ".mysql_error(); }; //If not, then... Well.. That sucks.

mysql_close($con); //Closes the connection made in the dbconnect.php script.

?>
Any ideas? :confused:
Skylear is offline   Reply With Quote
Old 07-21-2011, 10:36 PM   PM User | #2
nomanic
Regular Coder

 
nomanic's Avatar
 
Join Date: Feb 2009
Location: United Kingdom
Posts: 252
Thanks: 9
Thanked 33 Times in 33 Posts
nomanic is an unknown quantity at this point
none of your else statements close brackets, so the parser finishes the file incomplete

Code:
else {
    if($pass != $confirm_password) //Checks to see if the two passwords macth or not.
    { echo "Your passwords don't match."; }
should be

Code:
else {
    if($pass != $confirm_password) //Checks to see if the two passwords macth or not.
    { echo "Your passwords don't match."; }
}
for each of the else statements
nomanic is offline   Reply With Quote
Users who have thanked nomanic for this post:
Skylear (07-22-2011)
Old 07-22-2011, 12:47 AM   PM User | #3
Skylear
New Coder

 
Join Date: Jul 2011
Location: Kansas
Posts: 15
Thanks: 3
Thanked 0 Times in 0 Posts
Skylear is an unknown quantity at this point
Angry

Thanks, nomanic. I was stupid not to realize that. :P
But even after fixing it, my PHP Syntax checker (VERY useful!) built into my IDE said there was another parse error on line 36. >:/

PHP Code:
else { <--Line in question.
    if(
$checkemail != 0//if the email is already taken, it will display a message.
    
{ echo "Sorry, ".$email." is already registered.."; }
    }
else {
    if(
$username=""//Checks to see if the user actually inserted a username.
    
{ echo "Please provide a username."; } 
    }
else {
    if(
$password=""//Checks to see if the user actually inserted a password.
    
{ echo "Please provide a password."; } 
    }
else {
    if(
$email=""//Checks to see if the user actually inserted an email address.
    
{ echo "Please provide an email address."; }
    }
else {
$insert_user mysql>("INSERT INTO login (id, username, password, email, date, banned, level) VALUES(NULL, '$username', '$password', '$email', NULL, 'No', 'Member')"); 
      }; 
Skylear is offline   Reply With Quote
Old 07-22-2011, 01:41 AM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
@skylear: Click the coding styles link in my signature for some advice on your issue. You will see why when you get there.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 07-22-2011, 01:51 AM   PM User | #5
Skylear
New Coder

 
Join Date: Jul 2011
Location: Kansas
Posts: 15
Thanks: 3
Thanked 0 Times in 0 Posts
Skylear is an unknown quantity at this point
Thanks, tango, but I would prefer to stick with my current editor. All I need right now is a fix to this cursed parse error. :/
Skylear is offline   Reply With Quote
Old 07-22-2011, 02:11 AM   PM User | #6
XterM
New Coder

 
Join Date: Jul 2011
Location: Kediri - Indonesia
Posts: 61
Thanks: 2
Thanked 19 Times in 19 Posts
XterM is an unknown quantity at this point
i sure, code will do "insert new username" even when posted variable are empty. all check will return true, because you not compare the value. look:
PHP Code:
if($username=""
that's not mean "if $username is empty". so you need to compare values with just replace "=" with "==".
PHP Code:
if($username==""
then, you don't close any open statement. i moded your code to look better, so we easy to trace where is a problem, and i know if any unclosed statement on your code.

PHP Code:
<?php
//This is just starting a session.
session_start();

//Database info.
$dbhost "localhost";
$dbname "sky";
$dbuser "sky";
$dbpass "105000";

//Either this thing connects, or it's gunna die.
$con mysql_connect($dbhost$dbuser$dbpass) or die("MySQL Error: " mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " mysql_error());

//First, we store the information gathered from the form in variables.
$username=$_POST['username'];
$pass=$_POST['password'];
$email=$_POST['email'];

$password=md5($pass); //Here, we use the md5() function to encrypt the user's password.
$confirm_password=$_POST['confirmpass']; //NOW we store the confirmation password.
 

$queryuser=mysql>("SELECT * FROM people WHERE username='$username'");
$checkuser=mysql_num_rows($queryuser); //This query will check to see if the inserted username is already taken or not.

$queryemail=mysql>("SELECT * FROM people WHERE email='$email'");
$checkemail=mysql_num_rows($queryemail); //This does the same as the first query, but instead checks for the inserted email address.

if($checkuser != 0){ 
    echo 
"Sorry, ".$username." is already taken."
//If the username is already taken, it will display a message.
else {
    if(
$pass != $confirm_password){ 
        echo 
"Your passwords don't match."
    }
//Checks to see if the two passwords macth or not.
    
else {
        if(
$checkemail != 0){ //if the email is already taken, it will display a message.
            
echo "Sorry, ".$email." is already registered.."
        }
        else {
            if(
$username==""){ //Checks to see if the user actually inserted a username.
                
echo "Please provide a username."
            } 
            else {
                if(
$password==""){ //Checks to see if the user actually inserted a password.
                    
echo "Please provide a password."
                } 
                else {
                    if(
$email==""){ //Checks to see if the user actually inserted an email address.
                        
echo "Please provide an email address."
                    }
                    else {
//Inserts the data if everything checks out okay.
                        
$insert_user mysql>("INSERT INTO login (id, username, password, email, date, banned, level) VALUES(NULL, '$username', '$password', '$email', NULL, 'No', 'Member')"); 
                    }; 
 
                    if(
$insert_user//Did the information successfully insert into the database?
                    
{ echo "You successfully registered!"; } //If yes, then congrats!
                    
else
                    { echo 
"Gosh dang it, there was an error in registration. ".mysql_error(); }; //If not, then... Well.. That sucks.

                    
mysql_close($con); //Closes the connection made in the dbconnect.php script.

######### from here, you not close any statement, so just closed it #############
                
}
            }
        }
    }
}
############# eof ##############

?>
hope it helps
XterM is offline   Reply With Quote
Old 07-22-2011, 03:02 PM   PM User | #7
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by Skylear View Post
Thanks, tango, but I would prefer to stick with my current editor. All I need right now is a fix to this cursed parse error. :/
You will be seeing a lot more parse errors unless you change your STYLE of coding. I didn't suggest you change editors, my post uses Notepad++ but any editor is capable of using those coding styles.

If you always have your opening and closing braces {} on a seperate line and indented it makes your code far easier to read. Trust me, I used to code like you, it got sloppy and infuriating to fix. It's up to you if you want to listen to someone with experience or not.

Look at this:
PHP Code:
function a()
   {
   function 
b()
      {
      function 
c()
         {
         function 
d()
            {
            
//See how much easier this is to understand?
            
}
         }
      }
   } 
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Tags
closing, error, parse, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:18 PM.


Advertisement
Log in to turn off these ads.