views:

54

answers:

2

my scrip is supposed to look up contacts in a table and present thm on the screen to then be edited. however this is not this case. I am getting the error Parse error: syntax error, unexpected $end in /home/admin/domains/domain.com.au/public_html/pick_modcontact.php on line 50 NOTE: this is the last line in this script.

<?
session_start();

if ($_SESSION[valid] != "yes") {
    header( "Location: contact_menu.php");
    exit;
} 

$db_name = "testDB";
$table_name = "my_contacts";
$connection = @mysql_connect("localhost", "user", "pass") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());

$sql = "SELECT id, f_name, l_name FROM $table_name ORDER BY f_name";

$result = @mysql_query($sql, $connection) or die(mysql_error());

$num = @mysql_num_rows($result);

if ($num < 1) {
    $display_block = "<p><em>Sorry No Results!</em></p>";
} else {
    while ($row = mysql_fetch_array($result)) {
        $id = $row['id'];
        $f_name = $row['f_name'];
        $l_name = $row['l_name'];
        $option_block .= "<option value\"$id\">$l_name, $f_name</option>";
    }
    $display_block = "<form method=\"POST\" action=\"show_modcontact.php\">
    <p><strong>Contact:</strong>
    <select name=\"id\">$option_block</select>
    <input type=\"submit\" name=\"submit\" value=\"Select This Contact\"></p>
    </form>";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Modify A Contact</title>
</head>

<body>
<h1>My Contact Management System</h1>
<h2><em>Modify a Contact</em></h2>
<p>Select a contact from the list below, to modify the contact's record.</p>
<? echo "$display_block"; ?>
<br>
<p><a href="contact_menu.php">Return to Main Menu</a></p>
</body>
</html>
+4  A: 

You're not closing the } else { on line 22.

Add a } after the </form> bit, before you close the php section.

    </form>";
}
?>
Matt
sweet that worked. Im a newb so easy to miss. How come it said the error was on line 50 (last lin) and that erroe was on line 34?
Jacksta
Because the PHP interpreter was looking for that brace and was assuming it'd find it before hitting the `end-of-file`. It has no way of guessing where you want to close the `else` statement.
Matt
Never trust PHP to tell you the correct line. It probably has to do with the way PHP processes the code and gets all the way to the end until it realizes it's missing something.
patricksweeney
+2  A: 

An "unexpected end", especially with the error thrown on the last line, usually means a missing brace.

patricksweeney