1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Rep Power

    ECHO data from search form to table on same page

    How do I post the data to a results table when a user searches by last_name in a search form.

    <form action="." method="post" id="aligned"
                <label>Last Name</label>
                <input type="text" name="last_name" />
                <br />
                <input type="submit" value="Search" />
    The table I want the customer info to be displayed in.

    PHP Code:
      <td><?php echo $_POST['firstName'] .' '$_POST['last_name']; ?></td>
                    <td><?php echo $_POST['email']; ?></td>
                    <td><?php echo $_POST['city']; ?></td>
                    <td><form action="customer_display.php" method="post">
                        <input type="hidden" name="action" value="get_customer" />
                        <input type="hidden" name="customer_id"
                               value="<?php echo $_POST['customer_ID']; ?>" />
                        <input type="submit" value="Select" />
    Heres a function I have but not sure if I need it or how to implement it.
    PHP Code:
    function get_customers_by_last_name($last_name) {
    $query "SELECT * FROM customers
                WHERE lastName = '
                ORDER BY lastName"
    $customers $db->query($query);

  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Rep Power
    So the goal is to rewrite the second piece of code so that it displays the data retrieved from the database?

    There are two things you need to do:
    1. Call your function and pass the search value to it
    2. Change the HTML code in the second sample so that you use the array returned by the function instead of $_POST. Note that in addition to updating the array name, you may need to update the array indexes too; however, without seeing your database structure I don't know for sure.

    A useful way to view the structure of a complex variable is to use print_r. If you call print_r on the array returned by your function you will see exactly how it is structured and what elements it contains.

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo