Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse Error "unexpected $end" Driving me bananas!

Status
Not open for further replies.

luds

Programmer
Jul 15, 2003
162
GB
Hi!

I've got a page for members to register and/or login to, and a programme to access my mysql db, but whenever I click the submit button on the form page I keep getting:

"Parse error: parse error, unexpected $end in C:\Apache2\webs\Login200703.php on line 158

As I understand it, parse errors are equivalent to php going "Huh?? wtf is that??! lol" but I just can't see what's wrong with that line (?> !!!!!). It must be something that I've written previously, but what, I don't know!

Large though they are, I'll put the files below - "login_form" is the form page and "login200703" is the program. "dogs" is just my mysql username & password file.

Thanks

luds

*********"Login_form"********

<html>
<?php
/* File: login_form.inc
* Desc: Displays login page. Page displays two forms--one form for
* entering an existing login name and password and another
* form for the information needed to apply for a new account.
*/ // 7
?>

<head>
<title>Members Only Login</title>
</head>
<body topmargin=&quot;0&quot; leftmargin=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot;>
<table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot;>
<tr><td colspan=&quot;3&quot; bgcolor=&quot;gray&quot; align=&quot;center&quot;>
<font color=&quot;white&quot; size=&quot;+10&quot;>
<b>Members Only Section</b></font></td></tr>
<tr>
<td width=&quot;33%&quot; valign=&quot;top&quot;>
<font size=&quot;+1&quot;><b>Are you a member?</b></font>
<p>
<!-- form for customer login -->
<form action=&quot;Login200703.php?do=login&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;do&quot; value=&quot;new&quot;>

<table border=&quot;0&quot;>
<?php // 23
if (isset($message))
echo &quot;<tr><td colspan='2'>$message </td></tr>&quot;;
?>
<tr><td align=right><b>Username</b></td>
<td><input type=&quot;text&quot; name=&quot;fusername&quot; size=&quot;20&quot; maxsize=&quot;20&quot;>
</td></tr>
<tr><td width=&quot;120&quot; align=&quot;right&quot;><b>Password</b></td>
<td><input type=&quot;password&quot; name=&quot;fpassword&quot;
size=&quot;20&quot; maxsize=&quot;20&quot;></td></tr>
<tr><td align=&quot;center&quot; colspan=&quot;2&quot;>
<br><input type=&quot;submit&quot; name=&quot;log&quot; value=&quot;Enter&quot;></td></tr>
</table>
</form>
</td>
<td width=&quot;1&quot; bgcolor=&quot;gray&quot;></td>
<td width=&quot;67%&quot;>
<p><font size=&quot;+1&quot;><b>Not a member yet?</b></font> Get up to date information,
advance notice of forthcoming events and much more. Fill in the information
below and join. It's easy and free! </b>
<!-- form for new member to fill in -->
<form action=&quot;Login200703.php?do=new&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;do&quot; value=&quot;new&quot;>

<p>
<table border=&quot;0&quot; width=&quot;100%&quot;>
<?php
if (isset($message_new)) // 48
echo &quot;<tr><td colspan='2'><b>$message_new</b></td></tr>&quot;;
?>
<tr>
<td align=&quot;right&quot;><b>Member ID</b></td>
<td><input type=&quot;text&quot; name=&quot;newname&quot;
value=&quot;<?php echo $newname ?>&quot;
size=&quot;20&quot; maxlength=&quot;20&quot;></td>
</tr>
<tr>
<td align=&quot;right&quot;><b>Password</b></td>
<td><input type=&quot;password&quot; name=&quot;newpass&quot;
value=&quot;<?php echo $newpass ?>&quot;
size=&quot;10&quot; maxlength=&quot;8&quot;></td>
</tr>
<tr>
<td align=&quot;right&quot;><b>First Name</b></td>
<td><input type=&quot;text&quot; name=&quot;firstname&quot;
value=&quot;<?php echo $firstname ?>&quot;
size=&quot;40&quot; maxlength=&quot;40&quot;></td>
</tr>
<tr>
<td align=&quot;right&quot;><b>Last Name</b></td>
<td><input type=&quot;text&quot; name=&quot;lastname&quot;
value=&quot;<?php echo $lastname ?>&quot;
size=&quot;40&quot; maxlength=&quot;40&quot;></td>
</tr>
<tr>
<td align=&quot;right&quot;><strong>Age Group</strong></td>
<td><p>
<label> </label>
<label>
<input type=&quot;radio&quot; name=&quot;memberage&quot; value=&quot;under 10&quot;>
under 10</label>
<br>
<label>
<input type=&quot;radio&quot; name=&quot;memberage&quot; value=&quot;10-18&quot;>
10-18</label>
<br>
<label>
<input type=&quot;radio&quot; name=&quot;memberage&quot; value=&quot;19-34&quot;>
19-34</label>
<br>
<label>
<input type=&quot;radio&quot; name=&quot;memberage&quot; value=&quot;35-49&quot;>
35-49</label>
<br>
<label>
<input type=&quot;radio&quot; name=&quot;memberage&quot; value=&quot;50-64&quot;>
50-64</label>
<br>
<label>
<input type=&quot;radio&quot; name=&quot;memberage&quot; value=&quot;over 65&quot;>
over 65</label>
<br>
<br>
</p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td align=&quot;right&quot;><strong>What best describes you</strong> </td>
<td><p>
<label>
<input type=&quot;radio&quot; name=&quot;membercatagory&quot; value=&quot;Professional Singer&quot;>
Professional Singer</label>
<br>
<label>
<input type=&quot;radio&quot; name=&quot;membercatagory&quot; value=&quot;Singing Teacher&quot;>
Singing Teacher</label>
<br>
<label>
<input type=&quot;radio&quot; name=&quot;membercatagory&quot; value=&quot;Competition Supporter&quot;>
Competition Supporter</label>
<br>
</p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td align=&quot;right&quot;><strong>Nationality</strong></td>
<td><select name=&quot;membercountry&quot; size=&quot;1&quot;>
<option>
<option>AFGHANISTAN
<option>ALBANIA
<option>ALGERIA
<option>ARGENTINA
<option>ARMENIA
<option>AUSTRALIA
<option>AUSTRIA
<option>BELARUS
<option>BOSNIA AND HERZEGOWINA
<option>BOTSWANA
<option>BRAZIL
<option>BULGARIA
<option>CANADA
<option>CHILE
<option>CHINA
<option>COLOMBIA
<option>CROATIA (local name: Hrvatska)
<option>CUBA
<option>CZECH REPUBLIC
<option>DENMARK
<option>ECUADOR
<option>EGYPT
<option>EL SALVADOR
<option>ESTONIA
<option>FINLAND
<option>FRANCE
<option>GEORGIA
<option>GERMANY
<option>GIBRALTAR
<option>GREECE
<option>HONG KONG
<option>HUNGARY
<option>ICELAND
<option>IRAQ
<option>IRELAND
<option>ISRAEL
<option>ITALY
<option>JAPAN
<option>KENYA
<option>LEBANON
<option>LITHUANIA
<option>LUXEMBOURG
<option>NETHERLANDS
<option>NEW ZEALAND
<option>NORWAY
<option>Not Available
<option>PARAGUAY
<option>PERU
<option>POLAND
<option>PORTUGAL
<option>ROMANIA
<option>RUSSIAN FEDERATION
<option>SAMOA
<option>SINGAPORE
<option>SLOVAKIA (Slovak Republic)
<option>SLOVENIA
<option>SOUTH AFRICA
<option>SPAIN
<option>SRI LANKA
<option>SUDAN
<option>SWEDEN
<option>SWITZERLAND
<option>TAIWAN, PROVINCE OF CHINA
<option>TAJIKISTAN
<option>TANZANIA, UNITED REPUBLIC OF
<option>THAILAND
<option>TURKEY
<option>UKRAINE
<option selected>UNITED KINGDOM
<option>UNITED STATES
<option>UNKNOWN LOCATION
<option>URUGUAY
<option>UZBEKISTAN
<option>VENEZUELA
</select></td>
<td>&nbsp;</td>
</tr>
<tr>
<td align=right><b>Email Address</b></td>
<td><input type=&quot;test&quot; name=&quot;email&quot; value=&quot;<?php echo $email ?>&quot;
size=&quot;55&quot; maxlength=&quot;67&quot;></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align=&quot;center&quot;> <input type=&quot;submit&quot; value=&quot;Become a Member&quot;></td>
</tr>
</table>
</form>
</td>
</tr>
<tr><td colspan=&quot;3&quot; bgcolor=&quot;gray&quot;>&nbsp;</td></tr>
</table>
<div align=&quot;center&quot;><font size=&quot;-1&quot;> All comments and suggestions are appreciated.
Please send comments to <a href=&quot;mailto:webmaster@nationalmozart.com&quot;>webmaster@nationalmozart.com</A>
</font></div>
</body>

********&quot;Login&quot;********

<?php
/* Program: Login.php
Desc: Login program for the Members Only section of the
pet store. It provides two options: (1) login using an
existing Login Name and (2) enter a new login name. Login
Names and passwords are stored in a MySQL database.
*/
session_start(); // 8
session_register('auth'); // 9
session_register('logname');


include(&quot;C:/Apache2/webs/dogs.inc&quot;); // 11
switch (@$do) // 12
{
case &quot;login&quot;: // 14
$connection = mysql_connect($host, $user,$password) // 15
or die (&quot;Couldn't connect to server.&quot;);
$db = mysql_select_db($database, $connection)
or die (&quot;Couldn't select database.&quot;);

$sql = &quot;SELECT firstname FROM nmc_site_members // 19
WHERE firstname='$fusername'&quot;;
$result = mysql_query($sql)
or die(&quot;Couldn't execute query.&quot;);
$num = mysql_num_rows($result); // 23
if ($num == 1) // login name was found 24
{
$sql = &quot;SELECT firstname FROM nmc_site_members // 26
WHERE firstname='$fusername'
AND password=password('$fpassword')&quot;;
$result2 = mysql_query($sql)
or die(&quot;Couldn't execute query.&quot;);
$num2 = mysql_num_rows($result2);
if ($num2 > 0) // password is correct // 32
{
$auth=&quot;yes&quot;; // 34
$logname=$fusername; // 35
$today = date(&quot;Y-m-d h:m:s&quot;); // 36
$sql = &quot;INSERT INTO Login (firstname,loginTime)
VALUES ('$logname','$today')&quot;;
mysql_query($sql) or die(&quot;Can't execute query.&quot;);
header(&quot;Location: Member_page.php&quot;); // 40
}
else // password is not correct // 42
{
unset($do); // 44
$message=&quot;The Login Name, '$fusername' exists, // 45
but you have not entered the correct
password! Please try again.br>&quot;;
include(&quot;login_form&quot;); // 48
}
} // 50
elseif ($num == 0) // login name not found // 51
{
unset($do); // 53
$message = &quot;The Login Name you entered does not
exist! Please try again.<br>&quot;;
include(&quot;login_form&quot;);
}
break; // 58

case &quot;new&quot;: // 60
foreach($HTTP_POST_VARS as $key => $value) // 61
{
if ($key != &quot;fax&quot;) // 63
{
if ($value == &quot;&quot;) // 65
{
unset($do);
$message_new = &quot;Required information is missing.
Please try again.&quot;;
include(&quot;login_form&quot;);
exit();
}
}
if (ereg(&quot;{Name)&quot;,$key)) // 74
{
if (!ereg(&quot;^[A-Za-z' -]{1,50}$&quot;,$key))
{
unset($do);
$message_new = &quot;$firstname is not a valid name.
Please try again.&quot;;
include(&quot;login_form&quot;);
exit();
}

if (ereg(&quot;{Name)&quot;,$key)) // 74
{
if (!ereg(&quot;^[A-Za-z' -]{1,50}$&quot;,$key))
{
unset($do);
$message_new = &quot;$lastname is not a valid name.
Please try again.&quot;;
include(&quot;login_form&quot;);
exit();
}
}
$$key = strip_tags(trim($value)); // 85
}


if (!ereg(&quot;^.+@.+\\..+$&quot;,$email)) // 114
{
unset($do);
$message_new = &quot;$email is not a valid email address.
Please try again.&quot;;
include(&quot;login_form&quot;);
exit();
}

/* check to see if login name already exists */
$connection = mysql_connect($host,$user,$password) // 123
or die (&quot;Couldn't connect to server.&quot;);
$db = mysql_select_db($database, $connection)
or die (&quot;Couldn't select database.&quot;);
$sql = &quot;SELECT firstname FROM nmc_site_members
WHERE firstname='$newname'&quot;;
$result = mysql_query($sql)
or die(&quot;Couldn't execute query.&quot;);
$num = mysql_numrows($result);
if ($num > 0) // 132
{
unset($do);
$message_new = &quot;$newname already used. Select another
member ID.&quot;;
include(&quot;login_form&quot;);
exit();
}
else // 140
{
$today = time(&quot;Y-m-d&quot;);
$sql = &quot;INSERT INTO nmc_site_members (member_ID,createdate,password,
firstname,lastname,membersex,memberage,membercatagory,membercountry,
member_email) VALUES
('$newname','$today',password('$newpass'),
'$firstname', '$lastname','$membersex','$memberage','$membercatagory',
'$membercountry','$member_email')&quot;;
mysql_query($sql);
$auth=&quot;yes&quot;; // 150
$logname = $newname; // 151
/* send email to new member */ // 152
$emess1=&quot;A new Member Account has been setup for you. &quot;;
$emess2=&quot;Your new Member ID and password are: &quot;;
$emess3=&quot;\n\n\t$newname\n\t$newpass\n\n&quot;;
$emess4=&quot;We appreciate your interest in The National Mozart Competition &quot;;
$emess5=&quot;at nationalmozart.com\n\n&quot;;
$emess6=&quot;If you have any questions or problems, email &quot;;
$emess7=&quot;webmaster@nationalmozart.com&quot;;
$emess =
$emess1.$emess2.$emess3.$emess4.$emess5.$emess6.emess7;
$ehead=&quot;From: member-desk@petstore.com\r\n&quot;; // 162
$subject = &quot;Your new Member Account from THe National Mozart Competition&quot;;
$mailsend=mail(&quot;$email&quot;,&quot;$subject&quot;,&quot;$emess&quot;,&quot;$ehead&quot;);// 164
header(&quot;Location: New_member.php&quot;); // 165
}
}
?>
 
You're partially right. &quot;Parse error&quot; is not the PHP engine's way of saying &quot;I'm confused.&quot; -- it's the PHP engine's way of saying &quot;I just realized I'm confused&quot;. To my experience, the actual code error that generates the parse error never occurs at the line PHP reports.

&quot;Parse error, unexpected $end&quot; usually means that you don't have your brackets (&quot;{&quot;, &quot;}&quot;) balanced. The program flow gets to the end of the script, but PHP is still inside a code block somewhere.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
The code is not easily readable in this form.
Please post in TGML code tags [ignore]
Code:
....
[/ignore]

Indentation is lost like this - if you don't indent, make it a habit. It makes life easier.
 
luds,

Once again sleipnir214 has it correct. You are missing your closing set of curly braces for your switch statement.

HTH

Binky ::)
><>
 
Thanks!

Got that one sorted now....well.... no error messages when the submit button is clicked.....

...just a blank page, instead of the new member page! with in the address bar, which I'm sure should show the path to the new member page!

Any ideas?

thanks

luds
 
Examine the source of the page produced. There may be some partial HTML on it which can tell you where your script fails.

I also recommend you start footprinting your code for debugging purposes. Place print statements at critical points throughout your script. These can identify which parts of the script are running and which are not.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Thanks Sleipnir

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<META http-equiv=Content-Type content=&quot;text/html; charset=iso-8859-1&quot;>
</HEAD>
<BODY>
</BODY>
</HTML>

Suppose that tells me that the page that it should be going to is not being loaded lol

I'm intrigued by the print statement thing, though, Sleipnir... sounds a great idea. Any tutorials that you would recommend?

luds :¬)
 
You are interpreting your test results incorrectly. If you see the source you have listed, then the script is running, or at least parts of it are. I can't say what's going on with any certainty, because your programming style is to switch back and forth between &quot;HTML&quot; mode and &quot;execution&quot; mode in PHP, and that makes debugging more idiosyncratic.

I really can't recommend any tutorials from personal experience -- other than the code samples in the PHP manual, I've never used a PHP tutorial.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
The HTML you showed us is output when the script executes, but you don't echo or print anything to the browser.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top