Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 19th, 2003, 12:32 PM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shabboleth
Default Parse error on line that does not exist

Hello all,

I am getting a parse error on line 53 of a PHP document that vi shows as only having 52 lines. I am very new to PHP so I am sure it is something simple. Any help will be greatly appreciated.

Thanks,

Glen

Here is the document:

<?php
        $link = mysql_connect("localhost","user","password");
        $query = "SELECT * FROM jpnquiz.users";
        $result = mysql_query($query);
        $query_data = mysql_fetch_array($result);
?>
<html>
<head></head>
<body bgcolor="white" background="hiragana_bg.jpg">
<br>
<br>
<br>
<br>
<table border="1" align="center" width="50%">
<tr>
<td width="100%" align="center" bgcolor="white"><strong> Please select your name or enter the name by which you would like to be addressed.</td>
</tr>
</table>
<br>
<br>
<br>
<form method="post" action="savenewuser.php">
<table border="0" align="center" width="50%">
<?php
        If($query_data)
        {
        echo "<tr><td width=\"";
        echo "100%\" align=\"center\"><select name=\"selectuser\"><option value=\" \"> </option>";
        while($query_data=mysql_fetch_array($result))
        {
        echo "<option value = \"";
        echo $query_data["username"];

        echo "\">";
        echo $query_data["username"];
        echo "</option>";
        }
        echo "</select></td></tr>";
?>
<tr>
<td width="100%" align="center"><input type="text" size="20" maxlength="20" name="username"></td>
</tr>
<tr>
<td width="100%" align="center">&nbsp;</td>
</tr>
<tr>
<td width="100%" align="center"><input type="submit" value="Save"></td>
</tr>
</table>
</form>
</body>
</html>


 
Old December 19th, 2003, 01:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, you've got two open-curly-braces, but only one closing brace. PHP issues an error after the last line because the end of the file had been reached and the matching closing curly-brace was never found.

Open curly braces are on lines 26 and 30. Your only closing curly brace is on line 37.

Errors like this are almost always detected if you're more consistent with your indentation and formatting. Here's your code, reformatted:


<?php

if($query_data)
{
    echo "<tr><td width=\"";
    echo "100%\" align=\"center\"><select name=\"selectuser\"><option value=\" \"> </option>";

    while($query_data=mysql_fetch_array($result))
    {
        echo "<option value = \"";
        echo $query_data["username"];
        echo "\">";
        echo $query_data["username"];
        echo "</option>";
    }

    echo "</select></td></tr>";

?>


If this were properly nested, there'd be a closing curly-brace at column 0 (i.e. no indentation). After looking at the code, I think you need a closing curly-brace after your echo "</select>" line (line 39).


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: syntax error, unexpected T_ELSE in /h vipin k varghese BOOK: XSLT Programmer's Reference, 2nd Edition 4 September 29th, 2011 01:19 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
Parse error: syntax error, unexpected T_STRING ginost7 Beginning PHP 1 November 9th, 2007 02:51 AM
PHP Parse error: parse error, unexpected T_STRING geminient PHP How-To 4 August 18th, 2007 02:27 AM
Parse error: parse error, unexpected $end Ayodeji Adegbaju Pro PHP 3 January 12th, 2007 12:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.