Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Posts
    107
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Simple "IF" Script wont work.

    ok , so i wanted my script to check the rank collum from the users table.
    after finding the users rank

    i wanted it to check if it was greater than 3

    rank 4 & 5 is mod&admin , and so if it was i was going to include the admin
    control pannel.

    however, the script dosent seem to work.

    PHP Code:

    <?
    $result 
    mysql_query("SELECT * FROM users  LIMIT 1 ;");
    while(
    $row mysql_fetch_array($result))
      {
      echo 
    $row['pinboard'];
      }

    if (
    $row['rank'] >3);
    echo 
    "THIS IS WHERE I WILL INCLUDE THE ADMIN PANNEL";

    ?>
    the first part works fine (echo pinboard)
    that finds the users individual message within the pinboard row and displays it.

    but the rank part just seems to display the message regardless.
    any ideas?
    thanks in advance.

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    Your if statement isn't properly formatted. Try

    PHP Code:
    if ($row['rank'] >3) {
    echo 
    "THIS IS WHERE I WILL INCLUDE THE ADMIN PANNEL"

    Dave .... HostMonster for all of your hosting needs

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You need something here to determine what user you are trying to check or wise it will always return only the first user.
    PHP Code:
    $result mysql_query("SELECT * FROM users  WHERE userid = $id") or die(mysql_error()); 
    Where $id is a variable from either $_POST or $_GET. userid is your autoincrement column in your table for you database.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    IamHe (03-11-2009)

  • #4
    Regular Coder
    Join Date
    Mar 2009
    Posts
    107
    Thanks
    15
    Thanked 0 Times in 0 Posts

    You have an error in your SQL syntax;

    Thanks allot for the quick replys, my first time using this forum , was really suprised at the speed.

    i corrected the formatting as noted by dave in the first reply, and then i took aerospace's advice and added some more information to determain the user.

    now im getting.

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

    my script is in 2 parts, seperated by html.
    heres what it looks like.

    PHP Code:
    <?
    session_start
    ();
    include (
    'dbc.php');
    include (
    'functions.php');
    $result mysql_query("SELECT * FROM users  WHERE id = $id") or die(mysql_error());  
    while(
    $row mysql_fetch_array($result))

    ?>


      <?
    {
      echo 
    $row['pinboard'];
      }

    if (
    $row['rank'] >3) {
    echo 
    "THIS IS WHERE I WILL INCLUDE THE ADMIN PANNEL"
    }  

    ?>
    any ideas?
    thanks

  • #5
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    Where is $id being set?
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    IamHe (03-11-2009)

  • #6
    Regular Coder
    Join Date
    Mar 2009
    Posts
    107
    Thanks
    15
    Thanked 0 Times in 0 Posts
    i changed it to defineing by the users email. which is what they use to login.

    PHP Code:

    $user_email 
    $_GET['user_email'];
    $result mysql_query("SELECT * FROM users  WHERE user_email = $user_email") or die(mysql_error()); 
    and that posts from the login page. it posts fine. i cant figure it out , im still getting the error.

  • #7
    Regular Coder
    Join Date
    Mar 2009
    Posts
    107
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Ive just ran a little test.
    logging into 3 diffrent acounts.

    PHP Code:



     <?
      $result 
    mysql_query("SELECT * FROM users  LIMIT 1 ;");
    while(
    $row mysql_fetch_array($result))
    {
      echo 
    $row['pinboard'];
      echo 
    $row['rank'];
      echo 
    $row['pinboard'];
      echo 
    $row['full_name'];
      echo 
    $row['user_email'];
      }
      
      
    ?>
    it finds the users data perfectly , and displays , it , so i really cant understand whats going on. any ideas?

  • #8
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    PHP Code:
    <?php
    session_start
    ();
    include (
    'dbc.php');
    include (
    'functions.php');

    $user_email $_GET['user_email'];
    $sql "SELECT * FROM users  WHERE user_email ='" $user_email ."'";
    $result mysql_query($sql) or die(mysql_error());

    if (
    $result)
    {
        
    $row mysql_fetch_assoc($result);

        echo 
    $row['pinboard'];

        if (
    $row['rank'] >3
        {
            echo 
    "THIS IS WHERE I WILL INCLUDE THE ADMIN PANNEL"
        }
    }  

    ?>
    I strongly suggest you look into validating the user's input (ie: user_email), never trust ANY input from the user.

    You should also handle the situation where $result fails.
    John

  • Users who have thanked PappaJohn for this post:

    IamHe (03-11-2009)

  • #9
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    PHP Code:
    <? 
    session_start
    (); 
    include (
    'dbc.php'); 
    include (
    'functions.php'); 
    $query 'SELECT * FROM `users`  WHERE `user_email` = "'.$user_email.'"';
    $result mysql_query($query) or die(mysql_error());   
    while(
    $row mysql_fetch_array($result)) 

    ?> 


      <? 

      echo 
    $row['pinboard']; 
      } 

    if (
    $row['rank'] >3) { 
    echo 
    "THIS IS WHERE I WILL INCLUDE THE ADMIN PANNEL";  
    }else{
    echo 
    $row['rank'];
    }   

    ?>
    i changed the format on your query a little, see if that helps.

    i moved the query out of the actual mysql_query call. won't make much difference to you with this specifically, but it will make it easier when you get to more complex functions because you can change the query based on other variables blah blah

    anyway, i added an else statement. that way if your if statement isn't doing what you think it should, you might at least be able to figure out why by the output.

    also, you might consider using $_SESSION to store things like email instead of trying to pass it with a $_GET string.

  • Users who have thanked ohgod for this post:

    IamHe (03-11-2009)

  • #10
    Regular Coder
    Join Date
    Mar 2009
    Posts
    107
    Thanks
    15
    Thanked 0 Times in 0 Posts
    SOLVED

    Thanks allot to every one whose helped me out today!
    i really appreciate it.

    after the last post by oh god. i had a play round, and this is what it became.


    PHP Code:

    <? 
      $query 
    'SELECT * FROM `users`  WHERE `user_email` = "'.$_SESSION['user'].'"';
    $result mysql_query($query) or die(mysql_error());   
    while(
    $row mysql_fetch_array($result))  

    if (
    $row['rank'] >3) { 
    echo 
    "THIS IS WHERE I WILL INCLUDE THE ADMIN PANNEL";  
    }else{
    echo 
    "im an idiot";
    }   

    ?>
    thanks allot for your adivce.
    and session user works much better

    thanks again!

  • #11
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    change
    PHP Code:
    echo "im an idiot"
    to
    PHP Code:
    echo "i\'m an idiot"

  • Users who have thanked ohgod for this post:

    IamHe (03-11-2009)

  • #12
    Regular Coder
    Join Date
    Mar 2009
    Posts
    107
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ohgod View Post
    change
    PHP Code:
    echo "im an idiot"
    to
    PHP Code:
    echo "i\'m an idiot"
    See :P still an idiot.

    thanks allot for all your help

  • #13
    Regular Coder
    Join Date
    Mar 2009
    Posts
    107
    Thanks
    15
    Thanked 0 Times in 0 Posts
    i have another problem ,

    PHP Code:

    <?php
    session_start
    ();
    include
    "functions.php";
    include
    "dbc.php";
    $lr mysql_query("SELECT * FROM uonline ORDER BY id ASC;");
    while(
    $l mysql_fetch_array($lr))
    $mc 'SELECT * FROM `users`  WHERE `username` = "'.$_SESSION['user'].'"';
    while(
    $r mysql_fetch_array($mc))
      {
      echo 
    $l['session'];
      echo 
    " " $r['defaultpic'];

      }
      

    ?>
    its a users online script
    the actual function for users online is in functions.php
    that dose all the calculating, adding - taking away ,
    counting members online etc. but the idea for this script

    is just to diplsay the image and username , of all current members online.
    simple enough.... i thought , but im running into

    "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in usersonline.php on line 8""

    any ideas?thanks allot in advance

  • #14
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    You missed to query your DB
    PHP Code:
    $mc 'SELECT * FROM `users`  WHERE `username` = "'.$_SESSION['user'].'"';
    $result=mysql_query($mc ) or die(mysql_error());
    while(
    $r mysql_fetch_array($result)){
    ......... 
    Refer the manual http://php.net/mysql_query
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #15
    Regular Coder
    Join Date
    Mar 2009
    Posts
    107
    Thanks
    15
    Thanked 0 Times in 0 Posts
    New error::

    Query was empty

    but i have no idea what that means.

    before i stuck another query in after addding the first query advised above. it displayed the image fine.

    but after i added the second query it just shows that message.

    PHP Code:

    <?php
    session_start
    ();
    include
    "functions.php";
    include
    "dbc.php";
    $lr mysql_query("SELECT * = 'SELECT * FROM `uonline` LIMIT 3';");
    $result2=mysql_query($lr ) or die(mysql_error());

    while(
    $l mysql_fetch_array($lr))


    $mc 'SELECT * FROM `users`  WHERE `username` = "'.$l['session'].'"';
    $result=mysql_query($mc ) or die(mysql_error());

    while(
    $r mysql_fetch_array($mc)){
        
        
        
      {
      echo 
    $l['session'];
      echo 
    " " $r['defaultpic'];

      }
    }

    ?>
    Last edited by IamHe; 03-11-2009 at 06:05 PM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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