1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Another issue with my loops :(

Discussion in 'PHP' started by mintuz, Nov 21, 2010.

  1. #1
    Hi sorry about this, I have another issue with my script.

    I am getting the following errors.

    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\prototype2\control_panel.php on line 73

    Notice: Undefined variable: contact in C:\wamp\www\prototype2\control_panel.php on line 84

    here is the code.

    $sql="SELECT * FROM 'numbers' WHERE 'id' = '".$useridvar."'"; 
            $result=mysql_query($sql); 
                while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
                    { 
                        $contact = $row["number"]; 
                        $privacy_mode = $row["privacy_mode"]; 
                        $personal_number = $row["personal_number"]; 
                    } 
            echo '<div id="control_panel_info">'; 
              echo '<table width="200" border="0" cellpadding="4">'; 
                echo '<tr>'; 
                  echo '<td id="control_left_td">Your Current Contact :</td>'; 
                  echo '<td>'.$contact.'</td>'; 
                  
    PHP:
    The errors occur on

      while ($row = mysql_fetch_array($result, MYSQL_ASSOC))  
    PHP:
    and

    echo '<td>'.$contact.'</td>'; 
                  ?>
    PHP:
    however I think the last error occurs because I have noticed my while loop does not run. therefore the contact var is not going to have anything in it until the loop is ran. My userid session is set because at the top of the page I have a echo line which tells me the userid which is set from the database.

    Thanks.
     
    mintuz, Nov 21, 2010 IP
  2. namduong8889

    namduong8889 Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Everytime it gives that error it means you have written a wrong SQL query

    the query should be like this: (replace ' with ` on table and column names )
    
    "SELECT * FROM `numbers` WHERE `id` = '$useridvar'"
    
    PHP:
     
    namduong8889, Nov 21, 2010 IP
  3. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Always, always, always check return values :).

    
    <?php
        $sql = "SELECT * FROM 'numbers' WHERE 'id' = '".$useridvar."'";
        $result = mysql_query($sql); 
    
        if (!$result) die('Invalid query: ' . mysql_error());
    
        // rest of code..
    ?>
    
    PHP:
     
    Deacalion, Nov 21, 2010 IP
  4. mintuz

    mintuz Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    omg such a simple fix, ive been scratching my head for ages about it haha thankyou very much :)
     
    mintuz, Nov 21, 2010 IP