How to get the information from table to another page using PHP and MYSQL?

None other

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.

Jenz

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Transferring information from one table to another using PHP and MySQL

From Dev

How to Get VALUES from another table into another table in PHP/MySQL

From Dev

Get information from another website using PHP

From Dev

Mysql DELETE from table using information from another table

From Dev

Get information from another table using intermediate table

From Dev

How to get information from SQL table with php

From Dev

how to select photos from another table using mysql,php

From Dev

How to get data from one php page using ajax and pass it to another php page using ajax

From Dev

how can i get single value at next page from multiple values in another page using php

From Dev

How to select information from more then one table in MySQL Database using PHP and mySQli, has to be combined single query

From Dev

SQL: how to select something using information from another table

From Dev

PHP MYSQL Displaying the same data from table to another page

From Dev

How to get data from one Page in another page in php?

From Dev

how to get table in mysql using php

From Dev

Passing a value retrieved from a database to another page using php and mysql

From Dev

PHP MYSQL $_GET['ID'] from table on dynamically generated page

From Dev

Get value from mysql table in same cell as another value PHP

From Dev

How to get another table field information

From Dev

How to get count from another table (zero when no data) using single query in mysql?

From Dev

How to get count from another table (zero when no data) using single query in mysql?

From Dev

How to search for existence of record in one table from another using php and mysql

From Dev

How to send GET value and php available to another page using ajax?

From Dev

How to get codes from another page? (Basic PHP)

From Dev

How can I fetch information from database without using $ _GET and showing information in page

From Dev

how to get values from mysql using php?

From Dev

How do I get data from another table in MySQL?

From Dev

How do I get an id from a student in a list and display it the student's information on another page? Ruby on Rails

From Dev

How do I get one row of data from mySQL table using php?

From Dev

How to get last 7 days record from table as per date using PHP and MySQL

Related Related

  1. 1

    Transferring information from one table to another using PHP and MySQL

  2. 2

    How to Get VALUES from another table into another table in PHP/MySQL

  3. 3

    Get information from another website using PHP

  4. 4

    Mysql DELETE from table using information from another table

  5. 5

    Get information from another table using intermediate table

  6. 6

    How to get information from SQL table with php

  7. 7

    how to select photos from another table using mysql,php

  8. 8

    How to get data from one php page using ajax and pass it to another php page using ajax

  9. 9

    how can i get single value at next page from multiple values in another page using php

  10. 10

    How to select information from more then one table in MySQL Database using PHP and mySQli, has to be combined single query

  11. 11

    SQL: how to select something using information from another table

  12. 12

    PHP MYSQL Displaying the same data from table to another page

  13. 13

    How to get data from one Page in another page in php?

  14. 14

    how to get table in mysql using php

  15. 15

    Passing a value retrieved from a database to another page using php and mysql

  16. 16

    PHP MYSQL $_GET['ID'] from table on dynamically generated page

  17. 17

    Get value from mysql table in same cell as another value PHP

  18. 18

    How to get another table field information

  19. 19

    How to get count from another table (zero when no data) using single query in mysql?

  20. 20

    How to get count from another table (zero when no data) using single query in mysql?

  21. 21

    How to search for existence of record in one table from another using php and mysql

  22. 22

    How to send GET value and php available to another page using ajax?

  23. 23

    How to get codes from another page? (Basic PHP)

  24. 24

    How can I fetch information from database without using $ _GET and showing information in page

  25. 25

    how to get values from mysql using php?

  26. 26

    How do I get data from another table in MySQL?

  27. 27

    How do I get an id from a student in a list and display it the student's information on another page? Ruby on Rails

  28. 28

    How do I get one row of data from mySQL table using php?

  29. 29

    How to get last 7 days record from table as per date using PHP and MySQL

HotTag

Archive