Tech Support Guy banner
Status
Not open for further replies.

Parse error: syntax error

967 views 7 replies 2 participants last post by  Xsage 
#1 ·
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");
?>

Display data in table with edit button

Add New Data

effectexpiremoveindaysrecertification notificationunit#resident namedateleft90 day60 day 30 day
".$res[unit']."".$res['tenant']"".$res['effectdate']."".$res['expdate']."".$res['moveindate']."".$res['daysleft']."".$res['date90']."".$res['date60']."".$res['date30']."]Edit";
}
?>

[TR]

<?php

while($res = mysqli_fetch_array($result)) {
echo " ";
echo " ";
echo " "; // line 38
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo " ";
echo "
[TR][TD]

------------------------------------------------------------------
result:
Parse error: syntax error, unexpected '']."[/TD]"; ' (T_CONSTANT_ENCAPSED_STRING),
expecting ']' on line 38
 
See less See more
#2 ·
looks like you are missing a single quote on line 37:
echo "[TD]".$res[unit']."[/TD]";
changes to:
echo "[TD]".$res['unit']."[/TD]";
 
#4 ·
Line 38, you are missing a period:
echo "[TD]".$res['tenant']"[/TD]";
changes to:
echo "[TD]".$res['tenant']."[/TD]";
 
#6 · (Edited)
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);
?>

        Display data in table with edit button

        [URL=add.html]Add New Data[/URL]

        [TABLE]

        [TR]
            [TH][/TH]
            [TH][/TH]
            [TH]effect[/TH]
            [TH]expire[/TH]
            [TH]movein[/TH]
            [TH]days[/TH]
            [TH]recertification notification[/TH]
        [TR]
            [TH]unit#[/TH]
            [TH]resident name[/TH]
            [TH]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]".$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][URL=edit.php?id=".$res->id."]Edit[/URL]";
            }
        ?>
        [/TABLE]
 
#7 ·
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 'unit field is empty
';}
if(empty($tenant)) {echo 'tenant field is empty
';}
if(empty($effectdate)) {echo 'effectdate field is empty
';}
if(empty($expdate)) {echo 'expdate field is empty
';}
if(empty($moveindate)) {echo 'moveindate field is empty
';}
if(empty($daysleft)) {echo 'daysleft field is empty
';}
if(empty($date90)) {echo 'date90 field is empty
';}
if(empty($date60)) {echo 'date60 field is empty
';}
if(empty($date30)) {echo 'date30 field is empty
';}
} 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);
?>
 
#8 ·
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.
 
Status
Not open for further replies.
You have insufficient privileges to reply here.
Top