-2

Kept getting the error as shown with a screenshot. I have tried troubleshooting still left in the maze.

<?php 
include 'database.php';
session_start();
$pdo = Database::connect();
$test = $_SESSION['username'];
$sql = "SELECT companyname,companyaddress,country,companystate,email,mobile,companytype FROM company WHERE username= '" . mysql_real_escape_string($test) . "'";
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['companyaddress'] . '</td>';
echo '<td>'. $row['country'] . '</td>';
echo '<td>'. $row['companystate'] . '</td>';
echo '<td>'. $row['email'] . '</td>';
echo '<td>'. $row['mobile'] . '</td>';
echo '<td>'. $row['companytype'] . '</td>';
echo '<td width=250>';
echo '<a class="btn" href="read.php?username='.$row['username'].'">View Details</a>';
echo '&nbsp;';
echo '<a class="btn btn-success" href="update.php?username='.$row['username'].'">Update</a>';
echo '&nbsp;';
echo '<a class="btn btn-danger" href="delete.php?username='.$row['username'].'">Delete</a>';
echo '</td>';
echo '</tr>';
}
Database::disconnect();
?>

This is the error I keep getting.

Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20
Kehinde Adeoya
  • 31
  • 1
  • 2
  • 6

1 Answers1

0

Before use $_SESSION['username'] pls set his value

<?php 
session_start();
$_SESSION['username']=1;//Set value of session before use
include 'database.php';
$pdo = Database::connect();
$test = $_SESSION['username'];
$sql = "SELECT companyname,companyaddress,country,companystate,email,mobile,companytype FROM company WHERE username= '" . mysql_real_escape_string($test) . "'";
        foreach ($pdo->query($sql) as $row) {
        echo '<tr>';
        echo '<td>'. $row['companyname'] . '</td>';
        echo '<td>'. $row['companyaddress'] . '</td>';
        echo '<td>'. $row['country'] . '</td>';
        echo '<td>'. $row['companystate'] . '</td>';
        echo '<td>'. $row['email'] . '</td>';
        echo '<td>'. $row['mobile'] . '</td>';
        echo '<td>'. $row['companytype'] . '</td>';
        echo '<td width=250>';
        echo '<a class="btn" href="read.php?username='.$row['username'].'">View Details</a>';
        echo '&nbsp;';
        echo '<a class="btn btn-success" href="update.php?username='.$row['username'].'">Update</a>';
        echo '&nbsp;';
        echo '<a class="btn btn-danger" href="delete.php?username='.$row['username'].'">Delete</a>';
        echo '</td>';
        echo '</tr>';
        }
        Database::disconnect();
        ?>
Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20
  • Thanks. It's a global variable using session. The value has been set on the page I declared the session variable, and I'm just passing it as part of the query. you can substitute any other thing or it since it is just a string. – Kehinde Adeoya Oct 12 '15 at 10:01