Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: php error sql if

  1. #11
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Quote Originally Posted by keyboard1333 View Post
    Could someone please just explain to me really simply what I have to do. Also Traq there can be more than one user who's level == 9.
    A better question would be what are you trying to do? From the looks of your code, you're either trying to print out a list of users and flag which ones have level = 9, or you're selecting a specific user, determining if they have level = 9, and you're doing it wrong.
    - Josh

  2. #12
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    After a user logs in to the members area, if they have are an admin ( levels ==9) I would like it to display welcome admin

  3. #13
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    A better approach would be to determine that during the login, and then your scripts could refer to it whenever needed.

  4. #14
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Thanks for the suggesting traq, I will do that after i've gotten the actual script to work.

    PHP Code:
    $username1 '$username';
    $SQL "SELECT `id` FROM `users` WHERE `username`='$username1' AND `level`='9'";
    if( 
    mysql_num_rowsmysql_query$SQL ) ) === ){
    echo 
    "Welcome Admin";


    }else{  
    echo 
    "Welcome";

    Something in there is causing this error

    ( ! ) Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\echo time.php on line 104

  5. #15
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    where is line 104? post the dozen or so lines before that.

    also, is the user's username literally "$username" ? or is $username a variable that holds the actual username?

    seems like -everyone- is quoting their variables lately...???

  6. #16
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    PHP Code:
    <?php  

     mysql_connect
    ("localhost""root""") or die(mysql_error());  
     
    mysql_select_db("keyboard_test") or die(mysql_error());  
      

     if(isset(
    $_COOKIE['ID_my_site']))  
     {  
         
    $username $_COOKIE['ID_my_site'];  
         
    $pass $_COOKIE['Key_my_site'];  
              
    $check mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());  
         while(
    $info mysql_fetch_array$check ))       
             {  
      

             if (
    $pass != $info['password'])  
                 {             
    header("Location: login.php");  
                 }  
      
          
         else  
                 {  
                    
    $links "link2.php"
                 }  
             }  
             }  
     else  
      

     {              
     
    header("Location: login.php");  
     }  
      







    ?> 

    <?php  


    if (isset ($_POST['submit']))  

      
      





        
    $comment mysql_escape_string (trim (nl2br($_POST['comment'])));    

     
    // makes sure they filled it in
         
    if(!$_POST['comment']) {
             die(
    'You didn\'t enter a comment.');

    }

    $date date("d/m/y");
    $cheese =  "$comment <br /><hr /> ";   
    $guoc "<b>$username</b>";



    $sql mysql_query ("INSERT INTO comments (id,comments,name,date,ip) VALUES ('0','".$cheese."','".$guoc."','".$date."','" $_SERVER['REMOTE_ADDR']."')");  




         
       
         
        echo 
    '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><center>Your comment has been entered successfully!</center>'
        echo 
    '<center><form method="post" action="echo time.php">';
        echo 
    '<input type="submit" value="Click me" name="name"> <br />';
        echo 
    '</form>';
        echo 
    '</center>'
            
    }  
         
    else  



    ?> 


    <html> 
    <head> 



    </head> 
    <body> 
    <?php include("$links");  
    echo 
    "Hey <b> $username</b>"


    $username1 '$username';
    $SQL "SELECT `id` FROM `users` WHERE `username`='$username1' AND `level`='9'";
    if( 
    mysql_num_rowsmysql_query$SQL ) ) === ){
    echo 
    "Welcome Admin";


    }else{  
    echo 
    "Welcome";
    }  


     
    ?>
    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> 
    <p><b><u>COMMENTS</u></b></p> 
     




    <?php 
        
        
    // POST data wasnt entered, so display the comments and comment form  
        // view comments from database 
           
    $sql mysql_query ("SELECT * FROM comments  ORDER BY date DESC") or die(mysql_error());; 
           while (
    $row mysql_fetch_array ($sql)) { 
    ?>
    <table border="0" cellspacing="0" cellpadding="4" width="500">
    <tr>
    <td> 
    <?php 
    echo $row['name'].'<br />';      
    ?>
    </td>      
    <td>
    <?php 
    echo $row['date'].'<br />';      
    ?>
    </td> </tr>
    </table><br />
    <?php
           
    echo $row['comments'].'<br />';  
      







        echo 
    '<br /><br /> 
        <form action="echo time.php" method="post"> 
        Comments:<br /> 
        <textarea name="comment" cols="40" rows="7"></textarea> 
        <input type="submit" value="Submit" name="submit"> 
        </form>'


    ?> 
    <body style="background-color:lightgreen"> 
    </body> 
    </html>
    Thats the entire code. And $username is the name of the variable that holds the username

  7. #17
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    this line (101):
    PHP Code:
    echo "Hey <b> $username</b>" 
    has no ending semicolon.

    And if $username is a variable, don't quote it
    PHP Code:
    $username // works
    "$username// works (but no reason to do it like this)
    '$username' // don't works : / 

Bookmarks

Posting Permissions

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