-3

I am having syntax error with my following code

<?php 
If (!empty($_SESSION['LogedinStudentId'])) {
echo '<h3>Your Scholarship Applications:</h3>
<table width="100%" class="table table-bordered">
<tr>
<th scope="col">Sr.No.</th>
<th scope="col">Date of Application</th>
<th scope="col">Course Type</th>
<th scope="col">Course Description</th>
<th scope="col">Subject</th>
<th scope="col">Applied for Semester No.</th>
<th scope="col">Scholarship Status</th>
<th scope="col">View / Print</th>
</tr>
<tr>
<td>' . ++$serialno . '</td>
<td>' . if(empty($row_studentdashboard['DateofApplication'])) { 
echo '&nbsp;';
} else {
echo date("d-m-Y", strtotime($row_studentdashboard['DateofApplication']));
};
. '</td>
<td>' . $row_studentdashboard['CourseType'] .'</td>
<td>' . $row_studentdashboard['CourseDescriptionLong'] .'</td>
<td>' . $row_studentdashboard['Subject'] .'</td>
<td>' . $row_studentdashboard['ApplyForSemYear'] .'</td>
<td>' . $row_studentdashboard['ScholarshipStatus'] .'</td>
<td><a href="#">View</a> / <a href="#">Print</a></td>
</tr>
</table>';
} else {
echo '<h3>You do not have any application pending</h4>';
}
?>

I am getting syntax error on line no. 17 and 22. The second (nested) if statement is throwing syntax error. I can not judge what is wrong. If I run this second if statement outside of the html it is working fine. Can anyone point out what's wrong?

Kamlesh Panchal
  • 192
  • 2
  • 4
  • 20

3 Answers3

2

You 're not supposed to concatenate an if statement to a string. That is what you did on line 17/18

Peter Chaula
  • 3,456
  • 2
  • 28
  • 32
2

Try :

<?php 
    if (isset($_SESSION['LogedinStudentId']) && !empty($_SESSION['LogedinStudentId'])) {
        $out = '<h3>Your Scholarship Applications:</h3>';
        $out .= '<table width="100%" class="table table-bordered">';
        $out .= '<tr>';
        $out .= '<th scope="col">Sr.No.</th>';
        $out .= '<th scope="col">Date of Application</th>';
        $out .= '<th scope="col">Course Type</th>';
        $out .= '<th scope="col">Course Description</th>';
        $out .= '<th scope="col">Subject</th>';
        $out .= '<th scope="col">Applied for Semester No.</th>';
        $out .= '<th scope="col">Scholarship Status</th>';
        $out .= '<th scope="col">View / Print</th>';
        $out .= '</tr>';
        $out .= '<tr>';
        $out .= '<td>' . ++$serialno . '</td>';
        $out .= '<td>';
        if(!isset($row_studentdashboard['DateofApplication']) || empty($row_studentdashboard['DateofApplication'])) { 
            $out .= '&nbsp;';
        } else {
            $out .= date("d-m-Y", strtotime($row_studentdashboard['DateofApplication']));
        };
        $out .= '</td>';
        $out .= '<td>' . $row_studentdashboard['CourseType'] .'</td>';
        $out .= '<td>' . $row_studentdashboard['CourseDescriptionLong'] .'</td>';
        $out .= '<td>' . $row_studentdashboard['Subject'] .'</td>';
        $out .= '<td>' . $row_studentdashboard['ApplyForSemYear'] .'</td>';
        $out .= '<td>' . $row_studentdashboard['ScholarshipStatus'] .'</td>';
        $out .= '<td><a href="#">View</a> / <a href="#">Print</a></td>';
        $out .= '</tr>';
        $out .= '</table>';
    } else {
        $out  = '<h3>You do not have any application pending</h4>';
    }
    echo $out;
Fky
  • 2,133
  • 1
  • 15
  • 23
2

What you are doing is an if-statement inside of echo-statement. It is wrong. Run second if-statement outside of html and create a variable that you later print in your html. A kind of this:

if(empty($row_studentdashboard['DateofApplication'])) { 
$text = '&nbsp;';
} else {
$text = date("d-m-Y", strtotime($row_studentdashboard['DateofApplication']));
}

.....

<td>' . ++$serialno . '</td>
<td>' . $text . '</td>
Psytho
  • 3,313
  • 2
  • 19
  • 27