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.

Damn mysql_fetch_array and its errors

Discussion in 'PHP' started by BRUm, Nov 27, 2006.

  1. #1
    Hi,

    I've been tearing my hair out over this problem!

    
    <?php
    
    //Server, configure for incoming data
    //Connect to DB
    $hostname = "localhost";
    $mysql_login = "brum_***";
    $mysql_password = "***";
    $database = "brum_***"; 
    
    // connect to the database server
    if (!($db = mysql_pconnect($hostname, $mysql_login , $mysql_password))){
    die( "Can't connect to database server." );    
    }else{
    
    // select a database
    if (!(mysql_select_db("$database",$db))){
    die( "Can't connect to database." );
    }
    } 
    
    //Get information in cookies from the client
    $client_name = $_REQUEST['name'];
    $client_name_hashed = hash(md5, $client_name);
    
    //Get person's number of zombies from DB
    $search = "SELECT * FROM 'data' WHERE 'name_hashed' = $client_name_hashed";
    while($info = mysql_fetch_array( $search )){
    
    $server_name = $info['name'];
    $server_name_hashed = $info['name_hashed'];
    $zombies = $info['zombies'];
    
    }
    
    ECHO $server_name;
    ECHO "<br>".$server_name_hashed;
    ECHO "<br>".$zombies;
    
    //Below is debugging
    
    ECHO mysql_error();
    
    $debug = "INSERT INTO data (name, name_hashed, zombies) VALUES ('sam', '2832893237d2dew', '100')";
    mysql_query($debug);
    
    ?>
    
    PHP:
    I get the error:

    $debug works fine and writes to the DB, but this "while.." string doesn't work. If anyone has any ideas I'd be more than grateful.

    Thanks,

    Lee.
     
    BRUm, Nov 27, 2006 IP
  2. Big 'G'

    Big 'G' Member

    Messages:
    89
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    48
    #2
    you could try running the search first, this will give u a resource to use
    
    $search = "SELECT * FROM 'data' WHERE 'name_hashed' = $client_name_hashed";
    
    //TO
    $search =mysql_query("SELECT * FROM 'data' WHERE 'name_hashed' = $client_name_hashed");
    
    
    PHP:
     
    Big 'G', Nov 27, 2006 IP
    BRUm likes this.
  3. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #3
    Thanks for your help. I feel like I'm getting a little bit closer, but I still get the error, and a new one too:

     
    BRUm, Nov 27, 2006 IP
  4. lbalance

    lbalance Peon

    Messages:
    381
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #4
    take the single quotes ' out from around the column name, data
     
    lbalance, Nov 27, 2006 IP
    BRUm likes this.
  5. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #5
    I've already tried that :( Still doesn't work.
     
    BRUm, Nov 27, 2006 IP
  6. Big 'G'

    Big 'G' Member

    Messages:
    89
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    48
    #6
    
    SELECT * FROM 'data' WHERE 'name_hashed' = $client_name_hashed
    //TO
    SELECT * FROM 'data' WHERE name_hashed = '$client_name_hashed'
    
    PHP:
    Have moved the single quotes from the field to the value
     
    Big 'G', Nov 27, 2006 IP
  7. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It should be:
    $search = mysql_query ("SELECT * FROM `data` WHERE `name_hashed` = '$client_name_hashed' ");
    Code (markup):
    Notice the use of backticks (optional) and single quotes (not optional).
     
    exam, Nov 27, 2006 IP
  8. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #8
    Oh my god! I just realised ... the query was empty that's why! D'OH! Thanks guys :)
     
    BRUm, Nov 27, 2006 IP