Jump to content

Archived

This topic is now archived and is closed to further replies.

dual_alliance

PHP Error unexpected end

Recommended Posts

I have the following code:

[code]<?php

// Grab POST variables and convert then to variables

$first_name = $_POST['firstName'];
$last_name = $_POST['lastName'];
$username = $_POST['userName'];
$password = $_POST['passWord'];
$password2 = $_POST['passWord2'];
$email_address = $_POST['email'];
$email_address2 = $_POST['email2'];
$website = $_POST['website'];
$agree = $_POST['agree'];

// Store some needed HTML

// Top part of HTML

$topHTML = <<<tHTML

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Register</title>

<link href="style/main.css" rel="stylesheet" type="text/css" />

</head>

<body>

<div id="registererror"></div>

<div id="register2">

tHTML;

$ttopHTML = <<<ttHTML

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Register</title>

<link href="style/main.css" rel="stylesheet" type="text/css" />

</head>

<body>

<div id="registererror"></div>

<div id="register2">

ttHTML;


// Botton half of HTML

$botHTML = <<<bHTML

</div>

<div id="register3"></div>

<div id="botheader">

<p class="copyright">
All Rights Reserved, © Copyright dual_alliance 2006.
</p>

</div>

</body>

</html>

bHTML;

// Has the user accepted the terms and conidtions?

if($agree == "off"){

echo "Please agree to the terms and conditions to continue";

echo '$topHTML';

include('register_form.php');

echo '$botHTML';

  exit();

}

// Does the users passwords match?

if($password !== $password2){

echo "Passwords do not match, please re-enter your password";

echo '$topHTML';

include('register_form.php');

echo '$botHTML';

  exit();
}

// Does the users email addresses match?

if($email_address !== $email_address2){

echo "Email address' do not match, please re-enter your email address";

echo '$topHTML';

include('register_form.php');

echo '$botHTML';

  exit();

}


// Include MySQL Database Settings

include ('db.php');

// Remove HTML (if any)

$first_name = strip_tags($first_name);
$last_name = strip_tags($last_name);
$username = strip_tags($username);
$password = strip_tags($password);
$password2 = strip_tags($password2);
$email_address = strip_tags($email_address);
$email_address2 = strip_tags($email_address);
$website = strip_tags($websie);
$agree = strip_tags($agree);


// Any escaped characters?

$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$username = stripslashes($username);
$password = stripslashes($password);
$password2 = stripslashes($password2);
$email_address = stripslashes($email_address);
$email_address2 = stripslashes($email_address);
$website = stripslashes($websie);
$agree = stripslashes($agree);

// Any errors in the posted fields? Lets check...
// If there is an error, then we show the join form again
// so they can fill it out again. If everything
// checks out, then go ahead with your bad self!


// Has the user fill in all the required fields?


if((!$first_name) || (!$last_name) || (!$email_address) || (!$username) || (!$password) || (!email_address)){
    echo 'You did not submit the following required information! <br />';
    if(!$first_name){
        echo "First Name is a required field. Please enter it below.<br />";
    }
    if(!$last_name){
        echo "Last Name is a required field. Please enter it below.<br />";
    }
    if(!$email_address){
        echo "Email Address is a required field. Please enter it below.<br />";
    }
    if(!$username){
        echo "Desired Username is a required field. Please enter it below.<br />";
    }

    if(!$password){
        echo "Desired password is a required field. Please enter it below.<br />";
    }

echo '$topHTML';

include('register_form.php');

echo '$botHTML';

    exit();
}

// Connect to server and select database.

mysql_connect("$dbHost", "$dbUserName", "$dbPassWord")or die("Cannot connect to server!");
mysql_select_db("$dbName")or die("Cannot select Database!");

// Connect to server and select database.

mysql_connect("$dbHost", "$dbUserName", "$dbPassWord")or die("Cannot connect to server!");
mysql_select_db("$dbName")or die("Cannot select Database!");


   
// Does this user already exist in the database? lets check for that now...
$sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");

$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);

if(($email_check > 0) || ($username_check > 0)){
    echo "Please fix the following errors: <br />";
    if($email_check > 0){
        echo "<strong>Your email address has already been used by another member in our database. Please use a different Email address!<br />";
        unset($email_address);
    }
    if($username_check > 0){
        echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />";
        unset($username);
    }

// Show the form again

echo '$topHTML';

include('register_form.php');

echo '$botHTML';

    exit();
}

// everything checks out so far, so lets add this user!

$db_password = md5($password);

$member = 1;

/* Enter info into the Database.
I changed a little bit here from phpfreak's awesome tutorial on this subject. When I would get data from the user, I would not get an unencrypted password, only the md5 encrypted one. I couldn't use that, and me being the powertrip guy, I wrote in another little snippet to grab that password before it gets encrypted and stuff it into a blank variable, and write it to the database. Pretty nifty, eh?
*/

$sql = mysql_query("INSERT INTO users (userid, first_name, last_name, email_address, username, password, signup_date, activated, decrypted_password, member_group)
        VALUES('', '$first_name', '$last_name', '$email_address', '$username', '$db_password', now(), '$member', '$password', '$member')") or die (mysql_error());

if(!$sql){
    echo 'There has been an error creating your account. Please contact the webmaster.';
}else{

echo '$ttopHTML';

echo "You can login with the following details:<br />
Username: $username<br />
Password: $password<br />
Please keep this username and password in a location that is easily accessible by you.";

echo '$botHTML';

}

mysqlclose();

?>[/code]

But l get the error "
Parse error: syntax error, unexpected $end in /home3/alli4nc3/public_html/member/register_process.php on line 280" looking for an idea

thanks,

dual_alliance

Share this post


Link to post
Share on other sites
last line: change mysqlclose() to mysql_close()

you have several echo like this: echo '$botHTML';

if you wanted to print out the value in of a variable, use this:
echo $botHTML;

echo '$botHTML' will print $botHTML literately.

Share this post


Link to post
Share on other sites
Thanks, l made all the changes you suggested.  However it just comes up with another error (same one as before) but it says it's on line 277.  Heres the new code around line 277:

[code]if(!$sql){
    echo 'There has been an error creating your account. Please contact the webmaster.';
}else{

echo $ttopHTML;

echo "You can login with the following details:<br />
Username: $username<br />
Password: $password<br />
Please keep this username and password in a location that is easily accessible by you.";

echo $botHTML;

}

mysql_close();[/code]

thanks,

dual_alliance

Share this post


Link to post
Share on other sites
An error like that usually indicates either unbalanced curly braces "{ }" or unbalanced quotes (single or double).

Ken

Share this post


Link to post
Share on other sites
Thanks here is an update of my code:

[code]<?php

// Grab POST variables and convert then to variables

$first_name = $_POST['firstName'];
$last_name = $_POST['lastName'];
$username = $_POST['userName'];
$password = $_POST['passWord'];
$password2 = $_POST['passWord2'];
$email_address = $_POST['email'];
$email_address2 = $_POST['email2'];
$website = $_POST['website'];
$agree = $_POST['agree'];

// Store some needed HTML

// Top part of HTML

$topHTML = <<<tHTML

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Registration Error</title>

<link href="style/main.css" rel="stylesheet" type="text/css" />

</head>

<body>

<div id="registererror"></div>

<div id="register2">

tHTML;

$ttopHTML = <<<ttHTML

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Registration Complete</title>

<link href="style/main.css" rel="stylesheet" type="text/css" />

</head>

<body>

<div id="registercomplete"></div>

<div id="register2">

ttHTML;


// Botton half of HTML

$botHTML = <<<bHTML

</div>

<div id="register3"></div>

<div id="botheader">

<p class="copyright">
All Rights Reserved, © Copyright dual_alliance 2006.
</p>

</div>

</body>

</html>

bHTML;

// Has the user accepted the terms and conidtions?

if($agree == "off"){

echo "Please agree to the terms and conditions to continue";

echo $topHTML;

include('register_form.php');

echo $botHTML;

  exit();

}

// Does the users passwords match?

if($password !== $password2){

echo "Passwords do not match, please re-enter your password";

echo $topHTML;

include('register_form.php');

echo $botHTML;

  exit();
}

// Does the users email addresses match?

if($email_address !== $email_address2){

echo "Email address' do not match, please re-enter your email address";

echo $topHTML;

include('register_form.php');

echo $botHTML;

  exit();

}


// Include MySQL Database Settings

include ('db.php');

// Remove HTML (if any)

$first_name = strip_tags($first_name);
$last_name = strip_tags($last_name);
$username = strip_tags($username);
$password = strip_tags($password);
$password2 = strip_tags($password2);
$email_address = strip_tags($email_address);
$email_address2 = strip_tags($email_address);
$website = strip_tags($websie);
$agree = strip_tags($agree);


// Any escaped characters?

$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$username = stripslashes($username);
$password = stripslashes($password);
$password2 = stripslashes($password2);
$email_address = stripslashes($email_address);
$email_address2 = stripslashes($email_address);
$website = stripslashes($websie);
$agree = stripslashes($agree);

// Any errors in the posted fields? Lets check...
// If there is an error, then we show the join form again
// so they can fill it out again. If everything
// checks out, then go ahead with your bad self!


// Has the user fill in all the required fields?


if((!$first_name) || (!$last_name) || (!$email_address) || (!$username) || (!$password) || (!email_address)){
    echo 'You did not submit the following required information! <br />';
    if(!$first_name){
        echo "First Name is a required field. Please enter it below.<br />";
    }
    if(!$last_name){
        echo "Last Name is a required field. Please enter it below.<br />";
    }
    if(!$email_address){
        echo "Email Address is a required field. Please enter it below.<br />";
    }
    if(!$username){
        echo "Desired Username is a required field. Please enter it below.<br />";
    }

    if(!$password){
        echo "Desired password is a required field. Please enter it below.<br />";
    }

echo $topHTML;

include('register_form.php');

echo $botHTML;

    exit();
}

// Connect to server and select database.

mysql_connect("$dbHost", "$dbUserName", "$dbPassWord")or die("Cannot connect to server!");
mysql_select_db("$dbName")or die("Cannot select Database!");

// Connect to server and select database.

mysql_connect("$dbHost", "$dbUserName", "$dbPassWord")or die("Cannot connect to server!");
mysql_select_db("$dbName")or die("Cannot select Database!");


   
// Does this user already exist in the database? lets check for that now...
$sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");

$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);

if(($email_check > 0) || ($username_check > 0)){
    echo "Please fix the following errors: <br />";
    if($email_check > 0){
        echo "<strong>Your email address has already been used by another member in our database. Please use a different Email address!<br />";
        unset($email_address);
    }
    if($username_check > 0){
        echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />";
        unset($username);
    }

// Show the form again

echo $topHTML;

include('register_form.php');

echo $botHTML;

    exit();
}

// everything checks out so far, so lets add this user!

$db_password = md5("$password");

$member = 1;

/* Enter info into the Database.
I changed a little bit here from phpfreak's awesome tutorial on this subject. When I would get data from the user, I would not get an unencrypted password, only the md5 encrypted one. I couldn't use that, and me being the powertrip guy, I wrote in another little snippet to grab that password before it gets encrypted and stuff it into a blank variable, and write it to the database. Pretty nifty, eh?
*/

$sql = "INSERT INTO users (userid, first_name, last_name, email_address, username, password, signup_date, activated, decrypted_password, member_group)VALUES('', '$first_name', '$last_name', '$email_address', '$username', '$db_password', now(), '$member', '$password', '$member')";

// check if query successful

$result=mysql_query($sql) or die("Query failed : " . mysql_error());

if($result){

echo $ttopHTML;

echo "You can login with the following details:<br />";
echo "Username: $username<br />";
echo "Password: $password<br />";
echo "Please keep this username and password in a location that is easily accessible by you";

echo $botHTML;

mysql_close();
 
}else{

echo "There has been an error creating your account. Please contact the webmaster.";
mysql_close();
}

?>[/code]

Maybe my eyes are playing tricks on me as l cannot seem to find the problem.  Whatever l change, it still comes up with the same error just on a different line.  I really could use some help/advice.

Thanks

dual_alliance

Share this post


Link to post
Share on other sites
did you post the entired script?  I meant the entired file. include everything. from beg to end, even html, everything.

Share this post


Link to post
Share on other sites
you use <<< directive only if you have some thing to parse:
like this:

$myvar = 10;
$myhtml = <<<MYHTML
<title>$myvar</title>
<body></body>
MYHTML;

you know! if you want it to parse $myvar inside the block.


if you do not have anything to parse, DO NOT use that.
instead simply use the single quote:

$myhtml = '<title>$myvar</title>
<body></body>';


Share this post


Link to post
Share on other sites
Thankyou so much hvle l would have never thought of that, my script now works.

Thankyou once again

dual_alliance

Share this post


Link to post
Share on other sites

×

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.