No Error in Cpanel but nothing show in browser..
About my code, i need display $result of status by directly from browser “http://www.example.com/exp.php?status=pending” to show table off all pending.. but when i execute in browser only showing “”
i’m completely new in coding.. those code i get from online and sewing to get my application..
Any help will be very appreciated..
Thanks in advance
<?php require "templates/header.php"; ?>
<?php
session_start();
if(!$_SESSION['uname']){
header('Location: ../index.php');
}
require "../config.php";
require "../common.php";
if (isset($_GET['status'])) {
try {
$connection = new PDO($dsn, $username, $password, $options);
$status = $_GET['status'];
$sql = "SELECT * FROM users WHERE status = :status";
$statement = $connection->prepare($sql);
$statement->bindValue(':status', $status);
$statement->execute();
$result = $statement->fetch(PDO::FETCH_ASSOC);
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
} else {
echo "Something went wrong!";
exit;
}
?>
<?php
if (isset($_GET['status'])) {
if ($result->rowCount() > 0) { ?>
<h2>Results</h2>
<table>
<thead>
<tr>
<th>kode</th>
<th>imei</th>
<th>nama</th>
<th>tipe</th>
<th>kerusakan</th>
<th>harga</th>
<th>status</th>
<th>alasan</th>
<th>perubahan</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $row) { ?>
<tr>
<td><?php echo escape($row["kode"]); ?></td>
<td><?php echo escape($row["imei"]); ?></td>
<td><?php echo escape($row["nama"]); ?></td>
<td><?php echo escape($row["tipe"]); ?></td>
<td><?php echo escape($row["kerusakan"]); ?></td>
<td><?php echo escape($row["harga"]); ?></td>
<td><?php echo escape($row["status"]); ?></td>
<td><?php echo escape($row["alasan"]); ?> </td>
<td><a href="tutupservis.php?kode=<?php echo escape($row["kode"]); ?>">UPDATE</a></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } else { ?>
<blockquote>No results found for <?php echo escape($_POST['status']); ?>.</blockquote>
<?php }
} ?>
<a href="index.php">Kembali</a>
<?php require "templates/footer.php"; ?>
Only showing “templates/header.php”
I expect result to be shhowing in row of pending status
3
Answers
i have fix the problem by trial and error.. here is the code that showing my result.. thank for helping
The solution is changing $result = $statement->fetch(PDO::FETCH_ASSOC); to $result = $statement->fetchALL(PDO::FETCH_ASSOC);
your code doesn’t seem to have a problem. I don’t know, but
worked for me.
First, establish that
$_GET['status']
in your code is really getting data as desired so that you don’t have to worry about that in processing it.Start your php file with:
If that is displaying the data you meant for it, comment out the first two lines and proceed to build rest of your code. No result even after you verified the data through $_GET will point you in the right direction.