Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

puling individual data from a database....

Status
Not open for further replies.
Feb 13, 2005
2
GB
Hi there

i am new to programming with php and have a small problem i need to over come, what i am trying to do is pull data back from my database but make specific to the person who logged in, i can manage to insert data but i can pull any out, i think the problem is either the code i am using is wrong, or its not in the right dir.

i have accounts dir
in there is my php session
i have details.php which has clients details on
when they log in and go to details i want it to pull the details specific to that user using i would imagine

$result = mysql_query("SELECT * FROM customers
WHERE username ='$login'") or die(mysql_error());

and then would need to echomout the data once verified

$row = mysql_fetch_array( $result ); // Print out the contents of each row into a table
echo $row['phone']." - ".$row['email'];

i have cut it down to make it easy reading
i know the field names are correct bit i cant
pull any data back at all.

i need some code which will pull this back as per
the person who has logged in

any one have any ideas
its causing me great pain, i just want to put my foor through my poooter

cheers

Alan
 
does the sql actually return a value? ie is it correct, does the login name value get filled in? echo out the sql statement and debug it

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
Bastien,

when i echoed out $login it returned who ever loged in at that time, it also returned different values when different people logged in.

im not sure that i have inserted the code in the right Dir
its currently sat in the details dir and not sure if i can correspond to the login page.

i have to say its been doing my head in for days

when u say echo out the sql would i just add $sql
pardon me for looking stupid, just a bsic programer
at this time, no experience in de bugging.

regards

Alan
 
what bastien means is that you build the query as a string. echo the string and then pass the string as a variable to the query. eg
Code:
$sql = "select * from table";
echo $sql;
$results = mysql_query($sql);
 
$result = mysql_query("SELECT * FROM customers
WHERE username ='$login'") or die(mysql_error());

where dows "$login" come from? a form or created in the same php script? if $login comes from a form, it should be referenced as $_GET['login'] or $_POST['login'] depending the method you used in the form.

cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top