Small problem, Please help...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Small problem, Please help...

Post by Joe »

Recently I have been developing a new login system for my site. Now I have a problem that I just can't seem to solve. The problem is when a user logs in successfully I am trying to make it so it shows how many points they currently have. The code go's like:

$link = mysql_connect("???", "???", "???");
$activate = mysql_db_query ("???", "SELECT * FROM members WHERE username = '$username' AND password = '$password'");
$points1 = mysql_db_query ("???", "SELECT points from members WHERE username = '$username' AND password = '$password'");

if ($result = mysql_fetch_row($activate))
{
echo "<b>Welcome " . $username . " You currently have ". mysql_fetch_row($points1) . " points!</b><p>";
mysql_close($link);
}

Thats obviously just some of the code but can someone please help me. Another thing i should mention is when the user does login it says:

Welcome Joe You currently have Array points.

When it should actually say:

Welcome Joe You currently have 200 points.

Regards!


Joe
toms100
Forum Contributor
Posts: 119
Joined: Wed Feb 26, 2003 10:29 am
Location: Bristol,UK

Post by toms100 »

try:

Code: Select all

<?php
	$link = mysql_connect("HOST", "USERNAME", "PASSWORD");
	mysql_select_db("DATABASENAME",$link) or die("couldnt connect" . mysql_error());
	$activate = mysql_query("SELECT * FROM members WHERE username = '$username' AND password = '$password'",$link);
	while ($result = mysql_fetch_array($activate))
	{
		echo "<b>Welcome " . $result['username'] . " You currently have ". $result['points'] . " points!</b><p>";
	} 
	mysql_close($link);
?>
its pretty quick n dirty n nasty, but so long as you only have one row, it shouldnt matter!
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

And try :

Code: Select all

$link = mysql_connect('???', '???', '???') or die(mysql_error());
mysql_select_db('thedbname') or die(mysql_error());
$sql = "SELECT * FROM members WHERE username = '$username' AND password = '$password'";
$result = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($result)){
  $row = mysql_fetch_assoc($result);
  echo '<b>Welcome ' . $username . ' You currently have '.$row['points1'].' points!</b><p>';
}
Last edited by markl999 on Sun Feb 29, 2004 1:47 pm, edited 1 time in total.
toms100
Forum Contributor
Posts: 119
Joined: Wed Feb 26, 2003 10:29 am
Location: Bristol,UK

Post by toms100 »

try marks ;)
im not one for having the best code for the situation!
im sure mine would work, but marks is much more efficient
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

At least you got the mysql_select_db() in there, i missed it off mine the first time ;)
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Thanks

Post by Joe »

if (mysql_num_rows($result))
{
$row = mysql_fetch_assoc($result);
echo "<b>Welcome " . $username . " You currently have ". $row['points'] . " points!</b><p>";

That worked great. Thanks for your time and help people. Its just amazing to think I got that problem fixed within my first devnetwork forum post.

Regards



Joes :D
Post Reply