display personal info to user him/herself ONLY

Hi. I’m a super newbie to php and mysql. Please excuse me if my question is so basic.

On my website, users log in and purchase credits (real money) to buy some items.
( Simply, users pay real money through paypal and buy some game money to purchase game items)
When they purchase credits, their credit is updated to sql database.

I would like credits to be displayed when users logged in. displayed to the user him/herself only.

My simple rough algorithms planned is:

  1. call the table in which personal info is stored from database from sql by query

    <? mysql_connect("$host", "$uname", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");

    $musername = $_GET[‘user’];
    $sql=“SELECT * FROM $tbl_name2 WHERE usName=’$musername’”;
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    ?>

  2. confirm the userID is matching with the person who logged in.

  3. display the credit info using echo.

My question is the part 2.confirm.

Once I call the table name in sql, how do i confirm the person who is logged in? and how do I make the credit info is shown to the person who owns it…?

I extended your code a little to accomodate your requirements :wink:

[php]

<?php mysql_connect("$host", "$uname", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $musername = $_GET['user']; $sql="SELECT * FROM $tbl_name2 WHERE usName='$musername'"; $result = mysql_query($sql); /* i added this bit */ if($row = mysql_fetch_array($result)) { /* Success, output the credit info stored in $row['column name here'] and proceed with the script :) */ } else { /* Failed. do not show the info! and do something like show an error message or redirect the user maybe?? */ } ?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service