If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > code help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-30-09, 14:14
kingdavidbaker kingdavidbaker is offline
Registered User
 
Join Date: Nov 2009
Posts: 3
code help

Hello all. I'm trying to code the simple php IF statement below but it does not work properly. Basically it always returns the accepted condition. Wondering if there is something wrong with my query. It seems the query statement always returns a "1" value but I need to pull the actual data. Basically I need a query to give me the exact data located in a field and then check that result with my If statement.

$status = mysql_query("SELECT status FROM qls3_users WHERE username = '$username';");

if($status="IN") {
header("location: phpinfo.php");
exit();
}else {
header("location: login-failed.php");
exit();
}

Dunno if this is a PHP or MySql issue but any help would be greatly appreciated. Also just in case someone knows the statement above is set to redirect to "phpinfo.php" if accepted. I don't want to redirect to another page, I simply want it to show the current page if accepted and redirect if denied. I am using this to help deny multiple logins to my site and want to include this in the header of every page.
Reply With Quote
  #2 (permalink)  
Old 11-30-09, 14:26
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
Quote:
Originally Posted by kingdavidbaker View Post
Dunno if this is a PHP or MySql issue.
really
I don't see much MySQL here....

check your if statement == is not the same as =

if you are starting out developing PHP scripts then consider getting either a good qaulity PHP primer or get familiar with PHP tutorials from the lines of w3schools.net and of course the language site php.net
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 11-30-09, 15:05
kingdavidbaker kingdavidbaker is offline
Registered User
 
Join Date: Nov 2009
Posts: 3
Code Help

Thanks for the reply.

Yes there is only one mysql line but I'm not sure if it is correct. When I do a print $status or echo $status it just shows "Resource ID 21" but I need it to show the actual data located in that status field of the database. For instance echo $status should bring up "LoggedIn" or "LoggedOut"

What query do I have to create to retrieve the actual word written in the status field and then check that word with my IF statement?

$status = mysql_query("SELECT status FROM qls3_users WHERE username = '$username';");

I see there are mysql_fetch_field commands and things like that but I can't tell which I need to use. Once again any help would be greatly appreciated.
Reply With Quote
  #4 (permalink)  
Old 11-30-09, 15:48
kingdavidbaker kingdavidbaker is offline
Registered User
 
Join Date: Nov 2009
Posts: 3
Solved my issue. Used the mysql_result($status, 0); command and it gives me the data I want. Thanks!
Reply With Quote
  #5 (permalink)  
Old 11-30-09, 16:30
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
Nope you have merely ducked the issue
PHP Code:
if($status=="IN") {
header("location: phpinfo.php");
exit();
}else {
header("location: login-failed.php");
exit();

PHP: if - Manual
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #6 (permalink)  
Old 12-01-09, 12:18
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
also, why not throw the status condition into your SQL statement and then only get a record back when the status is IN? Then your if is more along the lines of record found or not found, should be faster.
Dave
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On