I have problem in connecting the information from the table to the other page. The table consists of information and there's a button to the right side named "View Information." When the user click the button, it will redirect to view_order.php. Inside the view_order.php, is the information in the table.
Please help me to figure this out. :)
<?php
session_start();
$conn = mysqli_connect('localhost','root','','sampsix');
if(mysqli_connect_errno()){
echo 'Failed to connect: '.mysqli_connect_error();
}
if(isset($_POST['delete'])){
$DeleteQuery = "DELETE FROM orders WHERE id='$_POST[hidden]'";
mysqli_query($conn,$DeleteQuery);
}
if(isset($_POST['view'])){
header('Location: view_order.php');
}
$query = "SELECT * FROM orders ORDER BY id";
$results = mysqli_query($conn,$query);
echo '<table border="1">';
echo '<tr>';
echo '<th>ID</th>';
echo '<th>Firstame</th>';
echo '<th>Lastname</th>';
echo '<th>Email</th>';
echo '<th>Order Name</th>';
echo '<th>Order Code</th>';
echo '<th>Order Qty</th>';
echo '<th>Sub Total</th>';
echo '</tr>';
while($orderData = mysqli_fetch_array($results)){
echo '<form action="order.php" method="POST">';
echo '<tr>';
echo '<td>'.$orderData['id'].'</td>';
echo '<td>'.$orderData['firstname'].'</td>';
echo '<td>'.$orderData['lastname'].'</td>';
echo '<td>'.$orderData['email'].'</td>';
echo '<td>'.$orderData['ordername'].'</td>';
echo '<td>'.$orderData['ordercode'].'</td>';
echo '<td>'.$orderData['orderqty'].'</td>';
echo '<td>'.$orderData['subtotal'].'</td>';
echo '<td><input type="hidden" name="hidden" value="'.$orderData['id'].'"></td>';
echo '<td><input type="submit" name="delete" value="Delete"></td>';
echo '<td><input type="submit" name="view" value="View Order"></td>';
echo '</tr>';
echo '</form>';
}
echo '</table>';
mysqli_close($conn);
?>
Here is the code of view_order.php
<?php
session_start();
include_once('config.php');
if(isset($_SESSION['id'])){
$id = $_SESSION['id'];
$query = $mysqli->query("SELECTid,firstname,lastname,email,ordername,ordercode,orderqty,subtotal FROM orders WHERE id='$id'");
if($query){
while($obj = $query->fetch_object()){
echo 'id: '.$obj->id;
echo 'Firstname: '.$obj->firstname;
echo 'Lastname: '.$obj->lastname;
echo 'Email: '.$obj->email;
echo 'Order Name: '.$obj->ordername;
echo 'Order Code: '.$obj->ordercode;
echo 'Order Qty: '.$obj->orderqty;
echo 'Sub Total: '.$obj->subtotal;
}
}
}
?>
None appears on the view_order.php. If there's error in my codes, please check it and suggest.
I don't think that FORM is needed in case. As I understood what you need is to redirect to the detailed page when you click View button. Instead of button, you can use hyperlink and pass the id through URL.
while($orderData = mysqli_fetch_array($results)){
// echo '<form action="order.php" method="POST">';
echo '<tr>';
echo '<td>'.$orderData['id'].'</td>';
echo '<td>'.$orderData['firstname'].'</td>';
echo '<td>'.$orderData['lastname'].'</td>';
echo '<td>'.$orderData['email'].'</td>';
echo '<td>'.$orderData['ordername'].'</td>';
echo '<td>'.$orderData['ordercode'].'</td>';
echo '<td>'.$orderData['orderqty'].'</td>';
echo '<td>'.$orderData['subtotal'].'</td>';
// echo '<td><input type="hidden" name="hidden" value="'.$orderData['id'].'"></td>';
//echo '<td><input type="submit" name="delete" value="Delete"></td>';
echo "<td><a href='view_order.php?id=".$orderData['id']."'>View</a></td>";
echo '</tr>';
//echo '</form>';
}
and in view_order.php
<?php
include_once('config.php');
if(isset($_GET['id'])){
$id = $_GET['id'];
$query = $mysqli->query("SELECT id,firstname,lastname,email,ordername,ordercode,orderqty,subtotal FROM orders WHERE id='$id'");
if($query){
while($obj = $query->fetch_object()){
echo 'Firstname: '.$obj->firstname;
}
}
}
?>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments