Welcome to WebmasterWorld Guest from 54.166.152.121

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Can someone please check my code?

Newbie just starting to experiment...

     
7:03 pm on Dec 24, 2005 (gmt 0)

5+ Year Member



I am getting the following errorParse error:

parse error, unexpected $ in /home/site/public/register2.php on line 107

Thing is that there is no line 107, my code ends at line 106.

Can someone help?

Thanks
Mitchell

<?php # Script 6.6 - register.php

$page_title = 'Register';
include ('header.inc');

if (isset($_POST['submit'])) {

$message = NULL;

if (empty($_POST['firstName'])) {
$fn = FALSE;
$message .= '<p>You forgot to enter your first name.</p>';
} else {
$fn = $_POST['firstName'];
}

if (empty($_POST['LastName'])) {
$ln = FALSE;
$message .= '<p>You forgot to enter your last name.</p>';
} else {
$ln = $_POST['LastName'];

if (empty($_POST['email'])) {
$e = FALSE;
$message .= '<p>You forgot to enter your email address.</p>';
} else {
$e = $_POST['email'];

if (empty($_POST['userName'])) {
$un = FALSE;
$message .= '<p>You forgot to enter your user name.</p>';
} else {
$un = $_POST['userName'];
}

if (empty($_POST['password'])) {
$pw = FALSE;
$message .= '<p>You forgot to makeup a password.</p>';
} else {
$ln = $_POST['password'];

if ($fn && $ln && $e && $un && $pw) {

require_once ('../mysql_connect.php');

$query = "INSERT INTO guestLog (firstName, LastName, email, userName, password, registration_Date) VALUES ('$fn', '$ln',
'$e', '$un', PASSWORD('$P'), NOW() )";
$result = @mysql_query ($query);

if ($result) {

echo '<p><b>You have been registered!</b></p>';
exit();

} else {

$message = '<p>You could not be registered because your friend is still a caveman and can\'t figure this stuff. Just
give him a few days to fix me.</p><p>' .mysql_error(). '</p>';

}

mysql_close();

} else {
$message .= '<p>Please try later.</p>';

}
}

if (isset($message)) {
echo '<font color="red">', $message, '</font>';

}

?>


<form action="<?php echo $_SERVER ['PHP_SELF'];?>" method="post">
<fieldset><legend>Enter your information in the form below:
</legend>

<p>First Name:
<input type="text" name="firstName" size="15" maxlength="30" value="<?php if (isset($_POST['firstName'])) echo $_POST['firstName'];?>" />
Last Name:
<input type="text" name="LastName" size="15" maxlength="30" value=""<?php if (isset($_POST['LastName'])) echo $_POST['LastName'];?>" />
</p>
<p>Email:
<input type="text" name="email" size="15" maxlength="30" value="<?php if (isset($_POST['email'])) echo $_POST['email'];?>" />
</p>
<p>User Name:
<input type="text" name="userName" size="15" maxlength="30" value="<?php if (isset($_POST['userName'])) echo $_POST['userName'];?>" />
Password:
<input type="text" name="password" size="15" maxlength="30" value="<?php if (isset($_POST['password'])) echo $_POST['password'];?>" />
</p>

</fieldset>

<div align="center"><input type="submit" name="submit" value="Register" /></div>

</form>

<?php
include ('footer.inc');
?>

10:15 pm on Dec 24, 2005 (gmt 0)

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Check all your:
if (empty($_POST['email'])) {
$e = FALSE;
$message .= '<p>You forgot to enter your email address.</p>';
} else {
$e = $_POST['email'];

This might be it, this error often points to a missing " } " somewhere and the error shows more lines that your script has for your PHP looks further down trying to get the missing item.

You are missing a whole bunch of closing " } "
(without " " )

you need an editor that hightlight bebinning and ending braces etc..

get in the habit to comment ending " } " in your scripts even if they are not 100% your own script
for ex: }// ends line 233.

Hope it helps did not test it

cheers

12:18 am on Dec 25, 2005 (gmt 0)

5+ Year Member



Opps you're right...

Still, having an error though. It's telling me to try again later, when I try to test it.

Has something to do with this:

if ($fn && $ln && $e && $un && $pw) {

require_once ('../mysql_connect.php');

$query = "INSERT INTO guestLog (firstName, LastName, email, userName, password, registration_Date) VALUES ('$fn', '$ln',
'$e', '$un', PASSWORD('$P'), NOW() )";
$result = @mysql_query ($query);

if ($result) {

echo '<p><b>You have been registered!</b></p>';
exit();

} else {

$message = '<p>You could not be registered because your friend is still a caveman and can\'t figure this stuff. Just
give him a few days to fix me.</p><p>' .mysql_error(). '</p>';

}

mysql_close();

} else {
$message .= '<p>Please try later.</p>';

}
}

3:06 am on Dec 25, 2005 (gmt 0)

10+ Year Member



every time I type a } (closing bracket)

I do this

}// end if/while/for whatever

Otherwise I'd already be in rehab or prison.

2:20 pm on Dec 25, 2005 (gmt 0)

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



OK add that to your script
if your script starts by SESSION...
then add it below the session otherwise add it to the top
and report what it says if it says something!
<?
error_reporting (E_ALL);
?>

Next just before it reads
if ($fn && $ln && $e && $un && $pw) {

try to echo each value
by:
echo"fn.$fn";
I have added before the variable its name so you will know which one is which
of course do it for all of those values

next I will delete completely the
line: if ($fn && $ln && $e && $un && $pw) {
and its beginning and ending braket
then execute the script and check your database to see if any value was added

Next: I will strip the script of most of its functions and will simply try to insert anything in your db

by the way explain us what is "try later" concept?

11:57 pm on Dec 25, 2005 (gmt 0)

5+ Year Member



Okay, Okay I fixed this script and I think it works. Being new to PHP I am just having "minor glitch" problems, like forget this or that. Now, I am having problems with my connection script. I am about to post a new topic. It's easy enough:

Parse error: parse error, unexpected T_ECHO in /home/mysql_connect.php on line 31

but no matter where I look - even line 31 - I can't seem to find what this means.

Please look for this next topic, I really need all the help I can get.

Thanks
Mitchell

2:29 pm on Dec 27, 2005 (gmt 0)

10+ Year Member



When it says unexpected "anything" usually that means the parser was expecting something else - like, a missing semicolon on the previous line, maybe.
7:15 pm on Dec 28, 2005 (gmt 0)

10+ Year Member



 if (empty($_POST['password'])) {
$pw = FALSE;
$message .= '<p>You forgot to makeup a password.</p>';
} else {
$ln = $_POST['password'];

Apart from the missing end bracket this should have $pw = $_POST['password'] and not $ln

also, further on your sql statement:

INSERT INTO guestLog (firstName, LastName, email, userName, password, registration_Date) VALUES ('$fn', '$ln',
'$e', '$un', PASSWORD('$P'), NOW() )";

should contain PASSWORD('$pw')?

 

Featured Threads

Hot Threads This Week

Hot Threads This Month