Results 1 to 6 of 6

Thread: code help

  1. #1
    Join Date
    Nov 2009
    Posts
    3

    Unanswered: 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.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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 on the Tiger 800 or the Norton

  3. #3
    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.

  4. #4
    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!

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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 on the Tiger 800 or the Norton

  6. #6
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •