Jump to content

Recommended Posts

I would like a general question answered for a self-taught php freak wanna-be.  I have successfully made my sql db, I have made great login and member pages.  BUT, now I want to reflect data of the logged in member on the member page.  Just like when you log into your credit card page, it shows YOUR current balance, previous balance, date you opened the account, etc.  Mine would show (and these are columns of data per member on my database)....

 

Contract Date:

Contract Expiration Date:

Amount Paid:

Contract Download (I want this pdf icon, when clicked, to download the contract that is stored as an object on my db.  I can handle the html a href side okay)

 

What is the php or html that would be used for "calling" (or whatever the term here is) this data on the current logged in member's page?

 

Thanks!

Edited by gordonp
  • 8 months later...

well you would want to do something like this

// Database Variables
define('DB_HOST', 'Database Host (Normally "localhost" if your script is on the same ip as the db');
define('DB_USER', 'Database User');
define('DB_PASSWORD', 'Database Password');
define('DB_DATABASE', 'Database Name');;

//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
    die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
    die("Unable to select database");
}
 
$table = "table you are pulling data from";
 
$query = "SELECT * FROM `table_name` WHERE account = 'account'";
//This is just an example where you can replace account with any column
 
$result = mysql_query($query) or die(mysql_error());
 
 
//Grab Information from query
 
if (mysql_numrows ($result) >= 1) {
        $rows = mysql_fetch_array ($result, MYSQL_ASSOC);

        foreach($rows AS $k => $v) {
            $$k = $v;
        }
        echo $Account_Paid; 
//assuming that that Account_Paid is a column name. You can do this with any of your column names in the database.
//you might need to change your file extension to .php in order to insert the variable on the page where you want to show the data unless you want to use something like Smarty.
//this can be it's own independent file if you want as well all you have to do is do include('path/to/this.php'); and then insert your variables.
}
Edited by Azerex

I am aware, sorry, this code is a snippet from one of my older programs so I didn't go through and fix any deprecated functions.

 

No problem, the comment was more directed at gordonp. It kind of sounds like he/she is just starting out with database programming and it's easier to make the switch now vs down the road.  :happy-04:

Are you visitors authenticated by a login system?

Do you have a session system setup?

 

If so, you can just do a SQL query using a WHERE clause based on some identifier from your $_SESSION array, such as a username or id (depends on how you've set it up) and then get the SQL array and echo them out where they need to go.

Edited by Clarkey
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.