保持获取错误,如屏幕截图所示。我已经尝试过在迷宫中留下的故障排除。
<?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 ' ';
echo '<a class="btn btn-success" href="update.php?username='.$row['username'].'">Update</a>';
echo ' ';
echo '<a class="btn btn-danger" href="delete.php?username='.$row['username'].'">Delete</a>';
echo '</td>';
echo '</tr>';
}
Database::disconnect();
?>
答案 0 :(得分:0)
使用前 $ _ SESSION [&#39;用户名&#39;] 请设置其值
<?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 ' ';
echo '<a class="btn btn-success" href="update.php?username='.$row['username'].'">Update</a>';
echo ' ';
echo '<a class="btn btn-danger" href="delete.php?username='.$row['username'].'">Delete</a>';
echo '</td>';
echo '</tr>';
}
Database::disconnect();
?>