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.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Mar 2004
    Location
    UK
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question mysql_fetch_array error

    Hi,

    I keep getting the following error and just can't figure out what the problem is. The query is definately fine, could it be anything to do with the username being a name and not a number?

    The code is as follows:
    PHP Code:
    if (isset($_SESSION['username']) AND ($_SESSION['privilege'] === 'a'))
    {    
    require_once (
    'mysql_connect.php'); // Connect to the database.
        
    $query "SELECT * FROM users WHERE users.username = {$_GET['username']}";

            
    $result mysql_query ($query);
        
    $row mysql_fetch_array ($resultMYSQL_ASSOC); 
    Any help would be much appreciated.

    Thanks,
    Paul

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    I keep getting the following error
    .. and the error is ...
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Depends on the time of year
    Posts
    478
    Thanks
    0
    Thanked 0 Times in 0 Posts
    from what i've seen so far (and yeah, i got to agree with firepages - what error message), that you're missing a closing curly bracket '}'

    Otherwise, if you mean error by "no output", then what you need to do is use a while loop:

    Code:
    if (isset($_SESSION['username']) AND ($_SESSION['privilege'] === 'a'))
    {    
    require_once ('mysql_connect.php'); // Connect to the database.
        $query = "SELECT * FROM users WHERE users.username = {$_GET['username']}";
    
            $result = mysql_query ($query);
      while (  $row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
     
          // do your thang here..
    
    } 
    }

  • #4
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jacko201

    The query is definately fine, could it be anything to do with the username being a name and not a number?

    No reason why that should make any difference jacko(unless of course you've got your username field set as an INT). I can't c any missing curly brackets like sum1 said above, in fact I can't see any problem with it at all. You might want to make the privilege comparison just an equivalent rather than exact match (i.e. "==" not "==="). It's hard to guess without seeing the actual error message, but is your mysql_connect script definitely working ok? As I can't see any problem with that at all. Also, this won't/shouldn't make any difference, but the "users.username" part is pointless, just have "username" . Hope this helps, but post the error!

  • #5
    New Coder
    Join Date
    Mar 2004
    Location
    UK
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh the error...sorry about that

    the error is...

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/cjpyec01/public_html/view_customer.php on line 256

    I've included the whole php code this time too.

    PHP Code:
    <?php 
    if (isset($_SESSION['username']) AND ($_SESSION['privilege'] === 'a'))
    {    
    require_once (
    'mysql_connect.php'); // Connect to the database.
        
    $query "SELECT * FROM users WHERE users.username = {$_GET['username']}";

            
    $result mysql_query ($query);
            (
    $row mysql_fetch_array ($resultMYSQL_ASSOC))
        
    // Item Details
          
    echo '<table border="0" width="80%" cellspacing="3" cellpadding="3" align="center">
                <tr><td bgColor=#80E7B7 align="right" width="35%"><b>Username:</b></td>'
    ;
                echo 
    "<td class=\"results_table\">{$row['username']}</td></tr>";
          
          echo 
    '<tr><td bgColor=#80E7B7 align="right" width="35%"><b>Registration Date:</b></td>';
                echo 
    "<td class=\"results_table\">{$row['registration_date']}</td></tr>";
        
          echo 
    '<tr><td bgColor=#80E7B7 align="right" width="35%"><b>Name:</b></td>';
                echo 
    "<td class=\"results_table\">{$row['forename']} {$row['surname']}</td></tr>";
             
          echo 
    '<tr><td bgColor=#80E7B7 align="right" width="35%"><b>Email:</b></td>';
                echo 
    "<td class=\"results_table\">{$row['email']}</td></tr>";
            
          echo 
    '<tr><td bgColor=#80E7B7 align="right" width="35%"><b>Phone:</b></td>';
                echo 
    "<td class=\"results_table\">{$row['phone']}</td></tr>";
        
          echo 
    '<tr><td bgColor=#80E7B7 align="right" width="35%"><b>Address:</b></td>';
                echo 
    "<td class=\"results_table\">{$row['address1']}<br> {$row['address2']}<br>  {$row['town']}<br> {$row['postcode']}</td></tr>";

                
          echo 
    '<tr><td bgColor=#80E7B7 align="right" width="35%"></td>';
                 echo 
    "<td><a href=\"edit_user.php?username={$row['username']}\">EDIT DETAILS</a> <br> <a href=\"delete_customer.php?username={$row['username']}\">DELETE CUSTOMER</a><td>";

    echo 
    "<br/>";
        
        } 
         else
        {
        echo 
    '<P>You are not authorised to view this page</p>';
        echo 
    'Please <a href = "login.php"> Login </a><br>';
        }
            
    mysql_close();// Closes the database connection.
        
    ?>
    If you've any idea what the problem could be please help!

    Many thanks
    Paul

  • #6
    New Coder
    Join Date
    Mar 2004
    Location
    UK
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh & yes, the mysql_connect works fine, tested it with other pages!

    Thanks for any help

  • #7
    New Coder
    Join Date
    Mar 2004
    Location
    UK
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    another mistake...

    the line below is like this...

    PHP Code:
    $row mysql_fetch_array ($resultMYSQL_ASSOC); 
    I changed it in post #5 to try dunigadnd's suggestion!

    Regards

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    ok , assuming users.username is a character field , you need to quote it in the query ...

    $query = " SELECT * FROM users WHERE users.username = '{$_GET['username']}' ";

    in fact in MySQL you can quote everything regardless of type apart from function calls , however if you want your SQL to be portable you should not quote integer types.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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