Jump to content


Photo

Having Problems Calling Specific Data From The Database.


  • Please log in to reply
13 replies to this topic

#1 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 28 June 2006 - 10:12 PM

I am making a site that requires you to have a membership. So the users must have there own account, which requires a username and password. I think you guys understand what I am saying.

I have the entire membership system set up and working, but I am having problems displaying information from the database. I want to display that specific person's information when they are logged in. Say there was a page that they could go to when they were logged in and it said something like:

Name:
Age:
Height:
Birthday:

I want it to display that persons data that I have saved in the database. But if someone else was logged into a different account, it would display their information.

When they login it registers their loginname and password as a session...but I am not sure how to use that in calling the information from the database. I have tried something like this:

$loop = mysql_query("SELECT * FROM players WHERE loginname=$loginname and password=$password")
or die ('cannot select people');

while ($row = mysql_fetch_array($loop)){

$username = $row['username'];
$money = $row['money'];



} //end loop

print "Username: $username";
print "<p>";
print "Money: $money";

But that doesn't get what I want. Could someone please push me in the right direction? Thanks.

#2 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 29 June 2006 - 12:22 AM

hmm, should be working, although i dont believe the password = $password bit needs to be there...

also you shouldnt need a while statement there if im correct, try something like this:

$loop = mysql_query("SELECT * FROM players WHERE loginname=$loginname")
or die('cannot select people');

$row = mysql_fetch_array($loop))

$username = $row['username'];
$money = $row['money'];


print "Username: $username";
print "<p>";
print "Money: $money";

UNTESTED

#3 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 29 June 2006 - 12:31 AM

How about...


// Retrieve all the data from the table
$result = mysql_query("SELECT * FROM players WHERE loginname=$loginname and password=$password") 
or die(mysql_error()); 

// store the record of the table into $row
$row = mysql_fetch_array( $result );

echo "$row[username]";
echo "<br>";
echo "$row[money]";



#4 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 29 June 2006 - 02:14 AM

localhost - Yours just gave me a blank screen.

realjumper - I think you are getting somewhere. I got an error like this:

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'and password=052588' at line 1

It grabbed the password from the database...?

I tried logging into a different account with different database information and it still grabbed the same password. It is just grabbing the information from the first row in the database for some reason.

#5 yong

yong
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 29 June 2006 - 02:39 AM

i only say my thinking....

Colin1388's method like "loginname=$loginname and password=$password" is not safe....

i think the username is not repeat...when someone register their information you must dispost the repeat

one

about SQL syntax i often use PHPMYADMIN is a good tool you can write SQL then exec that in PHPMYADMIN

the use information will show for you ....

my english is very poor i wish you can understand what i say...


#6 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 29 June 2006 - 03:22 AM

Yong - I do use PHPMYADMIN. I am not quite sure what you are trying to say though. How is it not safe? And what other way do you suggest doing it?

#7 Eugene

Eugene
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 29 June 2006 - 03:28 AM

the part password=$password needs to have single quotes. password = '$password' and the same for username.

#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 29 June 2006 - 04:37 AM

php way
<?php

$loop = "SELECT * FROM players WHERE loginname='$loginname' and password='$password' ";

$result=mysql_query($loop);

while ($row = mysql_fetch_assoc($result)){

$username = $row['username'];
$money = $row['money'];


echo $username;
echo"<br>";
echo $money;
} 
?>


php and html way

<?php

$loop ="SELECT * FROM players WHERE loginname='$loginname' and password='$password' ";

$result=mysql_query($loop);

while ($row = mysql_fetch_assoc($result)){

$username = $row['username'];
$money = $row['money'];

?>

<html>
<body>

<?php echo $username?>
<br>
<?php echo $money?>

<?php }>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 29 June 2006 - 05:11 AM

redarrow - None of those ways worked...The first one displayed everything but the information from the database, and the second way just gave me a blank screen.

#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 29 June 2006 - 07:10 AM

[!--quoteo(post=389116:date=Jun 29 2006, 05:11 AM:name=Colin1388)--][div class=\'quotetop\']QUOTE(Colin1388 @ Jun 29 2006, 05:11 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
redarrow - None of those ways worked...The first one displayed everything but the information from the database, and the second way just gave me a blank screen.
[/quote]
use my first example and do this.

under select statement.

echo $loop;

post your findings please cheers.
<?php

$db=mysql_connect("localhost","xxxxnamexxx","xxxpasswordxxxx");
mysql_select_db($db)or die("database not working");

$loop = "SELECT * FROM players WHERE loginname='$loginname' and password='$password' ";
echo $loop;

$result=mysql_query($loop);

while ($row = mysql_fetch_assoc($result)){

$username = $row['username'];
$money = $row['money'];


echo $username;
echo"<br>";
echo $money;
} 
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#11 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 29 June 2006 - 08:21 AM

$loop = "SELECT * FROM players WHERE loginname='$loginname' and password='$password' ";
where are you setting $loginname and $password? if you had a login form that calls this script, you need to at the very least do this:

$loginname = $_POST['loginname'];
$password = $_POST['password'];
$loop = "SELECT * FROM players WHERE loginname='$loginname' and password='$password' ";

also, you have this:
$username = $row['username'];
$money = $row['money'];
are you sure you have a column name in your table called 'username' and 'money' ?

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#12 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 29 June 2006 - 06:46 PM

Nothing is working...I am starting to wonder if I have my sessions setup wrong or something. Here is the code I am using now, I defined what loginname and password was.

<?php

include 'config.php';
include 'header.php';

$loginname = $_SESSION['loginname'];
$password = $_SESSION['password'];

$loop = "SELECT * FROM players WHERE loginname='$loginname' and password='$password' ";

$result=mysql_query($loop);

while ($row = mysql_fetch_assoc($result)){

$username = $row['username'];
$money = $row['money'];


echo $username;
echo"<br>";
echo $money;
} 

?>


#13 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 29 June 2006 - 08:51 PM

you need to start your script off with session_start(); in order to access the session variables:

<?php
session_start();
.
.
.
please note that it is at the beginning of anything else.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#14 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 01 July 2006 - 12:31 AM

I have everything working correctly now. Thanks for everyone who posted advice =D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users