Page 1 of 1

Parsing error

Posted: Wed Oct 28, 2009 4:00 am
by dgkindy
Can't seem to find the error. When I run the code, the error message says it is the last line of the code "?>" but can't see the problem. Help! Thanks
Parse error: parse error in D:\Documents and Settings\My Documents\My Websites\PETdb\example10-8.php on line 65

Code: Select all

<?php // sqltest.php
require_once 'login.php';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
 
if (!$db_server) die("Unable to connect to MySQL: ".mysql_error());
 
mysql_select_db($db_database, $db_server)
    or die("Unable to select database: " . mysql_error());
 
if (isset($_POST['code']) &&
    isset($_POST['term']) &&
    isset($_POST['definition']))  {
    
          $code = get_post('code');
          $term = get_post('term');
    $definition = get_post('definition');
 
    if (isset($_POST['delete']) && $code != "")
    {
        $query = "DELETE FROM tbl_definitions WHERE code='$code'";
 
        if (!mysql_query($query, $db_server))   
            echo "DELETE failed: $query<br />" .
            mysql_error() . "<br /><br />";
    }
    else
    {
        $query = "INSERT INTO tbl_definitions VALUES" .
        "('$code', '$term', '$defintion')";
 
        if (!mysql_query($query, $db_server))
            echo "INSERT failed: $query<br />" .
            mysql_error() . "<br /><br />";
    }
}
 
echo <<<_END
<form action="sqltest.php" method="post">
    <table border="1">
        <tr>
            <td width = "30%"><b>Code:</b> <input type="text" name="code" /></td>
            <td rowspan="2">Defintion <input type="text" name="definition"  maxlength="255" cols="80" rows="5" /></td>
        </tr>
        <tr>
            <td width = "30%"><b>Term:<b> <input type="text" name="term"        maxlength="35"  cols="40" /> </td>
        </tr>
    </table>
    <input type="submit" value="ADD RECORD" />
</form>
_END;
 
$query = "SELECT * FROM tbl_definitions";
$result = mysql_query($query);
 
if (!$result) die ("Database access failed: " . mysql_error());
$rows = mysql_num_rows($result);
 
for ($j = 0 ; $j < $rows ; ++$j)
{
    $row = mysql_fetch_row($result);
    echo <<<_END
    <table border="1">
        <tr>
            <td width = "30%"><b>Code:</b>  $row[2]</td>
            <td rowspan="2">$row[3]</td>
        </tr>
        <tr>
            <td width = "30%"><b>Term:</b>  $row[1]</td>
        </tr>
    </table>
<form action="sqltest.php" method="post">
<input type="hidden" name="delete" value="yes" />
<input type="hidden" name="code" value="$row[2]" />
<input type="submit" value="DELETE" /></form>
_END;
}
 
mysql_close($db_server);
 
function get_post($var)
{
    return mysql_real_escape_string($_POST[$var]);
}
?>
 

Re: Parsing error

Posted: Wed Oct 28, 2009 8:24 am
by superdezign
You sure it's the last line? There's more than 65 lines of code here...

Re: Parsing error

Posted: Wed Oct 28, 2009 2:55 pm
by dgkindy
Agree there are more then 65 lines. No I am not sure that the last line is the source of the error. The error message says that it is the last line. Either way, I don't see an error