Page 1 of 1
Simple SELECT query not working
Posted: Fri Nov 18, 2005 4:00 am
by mhouldridge
Hi,
I cannot figure out why this query and statement does not work, please help;
Code: Select all
$user = $_SESSION['userid'];
$query = mysql_query("SELECT signoff FROM users WHERE userid = '$user'");
if ($query['signoff'] == 0) {
echo '<a href=signoff.php?var=$userid class=blue2>You have not signed the Policies and Procedures form, click here now</a>';
}
The echo statement is printed all the time, therefore my query is not obtaining the user. Echo'ing my query does not come up within anything too.
Posted: Fri Nov 18, 2005 4:04 am
by AGISB
twigletmac | Please use Code: Select all
tags when posting PHP code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
$query is a recource not a variable.
Code: Select all
$user = $_SESSION['userid'];
$query = mysql_query("SELECT signoff FROM users WHERE userid = '$user'");
$signoff = mysql_fetch_row[$query];
if ($signoff[0] == 0) {
echo '<a href=signoff.php?var=$userid class=blue2>You have not signed the Policies and Procedures form, click here now</a>';
}
Posted: Fri Nov 18, 2005 4:09 am
by n00b Saibot
AGISB wrote:$query is a recource not a variable.
Code: Select all
$user = $_SESSION['userid'];
$query = mysql_query("SELECT signoff FROM users WHERE userid = '$user'");
$signoff = mysql_fetch_row[$query];
if ($signoff[0] == 0) {
echo '<a href=signoff.php?var=$userid class=blue2>You have not signed the Policies and Procedures form, click here now</a>';
}
first you should've used PHP Tags...
second mysql_fetch_row[$query]; should be mysql_fetch_row($query);
Posted: Fri Nov 18, 2005 4:43 am
by phpdevuk
I prefer to use mysql_fetch_assoc as opposed to mysql_fetch_row, it returns an associative array of fields from the db
Code: Select all
$user = $_SESSION['userid'];
$query = mysql_query("SELECT signoff FROM users WHERE userid = '$user'");
$signoff = mysql_fetch_assoc($query);
if ($signoff['signoff'] == 0) {
?><a href=signoff.php?var=<?= $userid ?> class=blue2>You have not signed the Policies and Procedures form, click here now</a><?
}
Posted: Fri Nov 18, 2005 5:10 am
by mhouldridge
Thankyou!