Parse error: syntax error

guitarzRus

Thread Starter
Joined
Jul 28, 2020
Messages
45
I'm trying to understand the error message I get with the following code. Thanks in advance.
--------------------------------------------------------------------
the code:
<?php
include_once("config.php");
$result = mysqli_query($mysqli, "SELECT * FROM certtbl ORDER BY id DESC");
?>

<html>
<head>
<title>Display data in table with edit button </title>
</head>

<body>
<a href="add.html">Add New Data</a><br><br>

<table width='50%'height='15%' border='1'>

<tr bgcolor='yellow'>
<th></th>
<th></th>
<th>effect</th>
<th>expire</th>
<th>movein</th>
<th>days</th>
<th colspan=3>recertification notification</th>
<tr>
<th>unit#</th>
<th>resident name</th>
<th colspan=3>date</th>
<th>left</th>
<th>90 day</th>
<th>60 day </th>
<th>30 day</th>
</tr>
<?php

while($res = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td bgcolor=''>".$res[unit']."</td>";
echo "<td>".$res['tenant']"</td>"; // line 38
echo "<td>".$res['effectdate']."</td>";
echo "<td>".$res['expdate']."</td>";
echo "<td>".$res['moveindate']."</td>";
echo "<td>".$res['daysleft']."</td>";
echo "<td>".$res['date90']."</td>";
echo "<td>".$res['date60']."</td>";
echo "<td>".$res['date30']."</td>";
echo "<td bgcolor='green'><a href='edit.php?id=$res[id]'><font color='white'>Edit</a>";
}
?>
</table>
</body>
</html>
------------------------------------------------------------------
result:
Parse error: syntax error, unexpected '']."</td>"; ' (T_CONSTANT_ENCAPSED_STRING),
expecting ']' on line 38
 

Xsage

Dave
Joined
Jan 8, 2016
Messages
332
looks like you are missing a single quote on line 37:
echo "<td bgcolor=''>".$res[unit']."</td>";
changes to:
echo "<td bgcolor=''>".$res['unit']."</td>";
 

guitarzRus

Thread Starter
Joined
Jul 28, 2020
Messages
45
now I get: unexpected '"</td>"' (T_CONSTANT_ENCAPSED_STRING), expecting ';' or ',' on line 38. I've been fighting this for days. please help.
 

Xsage

Dave
Joined
Jan 8, 2016
Messages
332
Line 38, you are missing a period:
echo "<td>".$res['tenant']"</td>";
changes to:
echo "<td>".$res['tenant']."</td>";
 

Xsage

Dave
Joined
Jan 8, 2016
Messages
332
That means you most likely have something between the:
<?php and while

Based on the example you provided in the first post and the two changes I suggested to it, I no longer get any further parsing errors.

Maybe you could re-post the new code as it is now?

Otherwise here is an example, I don't have a database to test with or your config, but here is an example I made of your code working:

PHP:
<?php

    class Item {
        public $id;
        public $unit;
        public $tenant;
        public $effectdate;
        public $expdate;
        public $moveindate;
        public $daysleft;
        public $date90;
        public $date60;
        public $date30;
       
        function __construct($id, $unit, $tenant, $effectdate, $expdate, $moveindate, $daysleft, $date90, $date60, $date30){
            $this->id = $id;
            $this->unit = $unit;
            $this->tenant = $tenant;
            $this->effectdate = $effectdate;
            $this->expdate = $expdate;
            $this->moveindate = $moveindate;
            $this->daysleft = $daysleft;
            $this->date90 = $date90;
            $this->date60 = $date60;
            $this->date30 = $date30;
        }
    }
   

    $item1 = new Item("1", "100", "Mr. A", "12/06/21", "20/06/21", "12/06/21", "10", "90", "60", "30");
    $item2 = new Item("2", "101", "Mr. B", "12/06/21", "20/06/21", "12/06/21", "10", "90", "60", "30");
    $item3 = new Item("3", "102", "Mr. C", "12/06/21", "20/06/21", "12/06/21", "10", "90", "60", "30");
    $item4 = new Item("4", "103", "Mr. D", "12/06/21", "20/06/21", "12/06/21", "10", "90", "60", "30");

    $result = array($item1, $item2, $item3, $item4);
?>

<html>
    <head>
        <title>Display data in table with edit button </title>
    </head>

    <body>
        <a href="add.html">Add New Data</a><br><br>

        <table width='50%'height='15%' border='1'>

        <tr bgcolor='yellow'>
            <th></th>
            <th></th>
            <th>effect</th>
            <th>expire</th>
            <th>movein</th>
            <th>days</th>
            <th colspan=3>recertification notification</th>
        <tr>
            <th>unit#</th>
            <th>resident name</th>
            <th colspan=3>date</th>
            <th>left</th>
            <th>90 day</th>
            <th>60 day </th>
            <th>30 day</th>
        </tr>
        <?php

            foreach($result as $res) {
                echo "<tr>";
                echo "<td bgcolor=''>".$res->unit."</td>";
                echo "<td>".$res->tenant."</td>";
                echo "<td>".$res->effectdate."</td>";
                echo "<td>".$res->expdate."</td>";
                echo "<td>".$res->moveindate."</td>";
                echo "<td>".$res->daysleft."</td>";
                echo "<td>".$res->date90."</td>";
                echo "<td>".$res->date60."</td>";
                echo "<td>".$res->date30."</td>";
                echo "<td bgcolor='green'><a href='edit.php?id=".$res->id."'><font color='white'>Edit</a>";
            }
        ?>
        </table>
    </body>
</html>
 
Last edited:

guitarzRus

Thread Starter
Joined
Jul 28, 2020
Messages
45
Please help me understand these error messages:

Parse error: syntax error, unexpected '{' on line 19
Parse error: syntax error, unexpected 'if' (T_IF) on line 20 if I // the {
------------------------------------------------------------------------
the code:
<?php
include_once("config.php");
if(isset($_POST['update']))
{
$id = mysqli_real_escape_string($mysqli, $_POST['id']);
$unit = mysqli_real_escape_string($mysqli, $_POST['unit']);
$tenant = mysqli_real_escape_string($mysqli, $_POST['tenant']);
$effectdate = mysqli_real_escape_string($mysqli, $_POST['effectdate']);
$expdate = mysqli_real_escape_string($mysqli, $_POST['expdate']);
$moveindate = mysqli_real_escape_string($mysqli, $_POST['moveindate']);
$daysleft = mysqli_real_escape_string($mysqli, $_POST['daysleft']);
$date90 = mysqli_real_escape_string($mysqli, $_POST['date90']);
$date60 = mysqli_real_escape_string($mysqli, $_POST['date60']);
$date30 = mysqli_real_escape_string($mysqli, $_POST['date30']);

if(empty($unit) || empty($tenant) || empty($effectdate) || empty($expdate)
|| empty(moveindate) || empty(daysleft) || empty(date90) || empty(date60)
|| empty(date30)
{ // line19
if(empty($unit)) {echo '<font color="red">unit field is empty</font><br>';}
if(empty($tenant)) {echo '<font color="red">tenant field is empty</font><br>';}
if(empty($effectdate)) {echo '<font color="red">effectdate field is empty</font><br>';}
if(empty($expdate)) {echo '<font color="red">expdate field is empty</font><br>';}
if(empty($moveindate)) {echo '<font color="red">moveindate field is empty</font><br>';}
if(empty($daysleft)) {echo '<font color="red">daysleft field is empty</font><br>';}
if(empty($date90)) {echo '<font color="red">date90 field is empty</font><br>';}
if(empty($date60)) {echo '<font color="red">date60 field is empty</font><br>';}
if(empty($date30)) {echo '<font color="red">date30 field is empty</font><br>';}
} else {
$result = mysqli_query($mysqli, "UPDATE certtbl SET
unit='$unit',tenant='$tenant',effectdate='$effectdate',expdate='$expdate',
moveindate='$moveindate',daysleft='$daysleft',date90='$date90',date60='$date60',
date30='$date30'
WHERE id=$id");
header("Location: Ndex.php");
}
}
?>
----------------------------------------------
config code:
<?php
$databaseHost = 'localhost';
$databaseName = 'prerentdb';
$databaseUsername = 'root';
$databasePassword = '';
$mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword,
$databaseName);
?>
 

Xsage

Dave
Joined
Jan 8, 2016
Messages
332
At the end of your if statement, you are missing a closing bracket to the statement as a whole e.g:
if(...)

So change:
|| empty(date30)
to:
|| empty(date30))

Also you might be missing the $ from half of those in that if statement.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top