PHP Get SQL Value Link to

Any problem with PHP can be disscused here
Locked
reece
Posts: 55
Joined: Tue Apr 04, 2006 10:59 am

PHP Get SQL Value Link to

Post by reece »

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/reece.awardspace.co.uk/login.php on line 49

Warning: Cannot modify header information - headers already sent by (output started at /home/www/reece.awardspace.co.uk/login.php:49) in /home/www/reece.awardspace.co.uk/login.php on line 54

i have tryed to make it get the url from the database and the link
so it gets 'priv' from database so when continue is **** it will get priv for that user eg.admin.php

Code: Select all


 // hand over the request
$results = mysql_query($request);

// if mysql returns any number of rows great than 0 then there is a succesful login
if(mysql_num_rows($results))
{
// get information on user
$mysql_user = mysql_real_escape_string($user);
$query= "SELECT `user`, `priv` FROM `$dbtable` WHERE username='$mysql_user' LIMIT 1";
$rs = mysql_query($query);
$result = mysql_fetch_array($rs);
$userid = $result['userid'];
$priv = $result['priv'];

$html_user = htmlentities($user);
setcookie('userid', $userid, time() + 3600, '/', '', 0);
echo "You have successfuly loged in! Welcome, $html_user .

<a href=\"$priv\">Continue...</a>"; 
}

thanks in advance

reece


reece
Posts: 55
Joined: Tue Apr 04, 2006 10:59 am

Post by reece »

mohumben
Posts: 82
Joined: Thu Sep 15, 2005 9:45 pm

Post by mohumben »

First, there is an edit button. I am not moderator or admin here but it's just good knowledge.

Now, about your script.

1. Your script is throwing a Warning, "headers already sent by", which means you sent output prior to calling header(), and shouldn't happen.

2. mysql_num_rows() will return the number of rows. Instead of using if(mysql_num_rows($query)) I would use if (mysql_num_rows($query) == 1)

3. Don't use $user, but $_POST['user'] or $_GET['user'] depending on your script.

4. I wonder why you are querying user data again if you did this before.

5. About your "main" error, I am not pretty sure why it's happening, but if you post your entire script it would help...
reece
Posts: 55
Joined: Tue Apr 04, 2006 10:59 am

sorted

Post by reece »

its ok i have sorted this now thanks
Locked