Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Search for PK and show all relating data

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Search for PK and show all relating data

Postby qwerty255 » Sun Mar 10, 2013 7:57 am

Hi all,

I was hoping someone could help me with something I wish to create.

I wish to create something like a login page but instead of name and password, you use a 'Customer Number' which searches the 'Customer' database to see if the entered customer number exists, and if it does, redirect into the system to another page which outputs all the data relating to that customer number, e.g.

Customer number: 900800700
Customer Name: James May
Customer Purchase Date: 12/08/2012
Location: London, England

etc.

I want to get whatever has been entered into the box and return the data above and more, but have no idea how i'd go about doing this.

Any help that you guys could give would be lovely.
qwerty255
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sun Mar 10, 2013 7:52 am

Re: Search for PK and show all relating data

Postby seandisanti » Mon Mar 11, 2013 8:14 am

You're sure you want to make all of your order information visible to whomever puts in a number? Personally I think that's a horrible idea, but only damaging to yourself and your business so I'm happy to help. I've made some assumptions here based on the limited info provided. The assumptions are:
1) that you are properly using PDO for your database access, the type of database doesn't matter
2) that you have a database object with a 'getInstance()' method that returns a connection to your database
3)all table and row names are assumptions
Code: Select all

<?php

if ($_POST) {//assuming your form posts to this script
    
$db Database::getInstance();
    
$custNo $_POST['custNo'];
    
$sql "SELECT * FROM orders where customer_number = " $custNo;
    
$result $db->query($sql);
    if ((!
$result) || $result->rowCount() == 0) {
        return 
false//query error or no records for that custNo
    
}
    echo 
'<table>';
    while (
$row $result->fetch(PDO::FETCH_ASSOC)) {
        echo 
'<tr><td>' $row['product_number'] . '</td><td>' $row['product_description'] . '</td><td>' $row['qty'] . '</td><td>' $row['order_date'] . '</td></tr>';
    }
    echo 
'</table>';
}
 
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 787
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron