-3

I am getting parse error unexpected IF (T_IF). please help me correcting my code i have session_start() before tag and using session username for selecting row from database. please help me my code is not working properly

PHP CODE

<?php
// connect to the database
include('connect-db.php');
$username = $_SESSION['username']
// get the records from the database
if ($result = $mysqli->query("SELECT * FROM user WHERE username = '$username'"))
{
// display records if there are records to display
if ($result->num_rows > 0)
{
// display records in a table
echo "<table border='1' cellpadding='10'>";

// set table headers
echo "<tr><th>ID</th><th>First Name</th><th>Last Name</th><th></th><th></th></tr>";

while ($row = $result->fetch_object())
{
// set up a row for each record
echo "<tr>";
echo "<td>" . $row->id . "</td>";
echo "<td>" . $row->firstname . "</td>";
echo "<td>" . $row->lastname . "</td>";
echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a></td>";
echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a></td>";
echo "</tr>";
}

echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
echo "No results to display!";
}
}
// show an error if there is an issue with the database query
else
{
echo "Error: " . $mysqli->error;
}

// close database connection
$mysqli->close();

?>
aditya
  • 11
  • 1
  • 4

1 Answers1

3

You are getting this error because you are missing a semi-colon ; to terminate the line on line number 4 of above mentioned code i.e.

$username = $_SESSION['username']

Terminate the line like (see the added semicolon) and issue will be resolved.

$username = $_SESSION['username'];
Qirel
  • 25,449
  • 7
  • 45
  • 62