Simple Code - Retrieving info from mysql.. WHATS WRONG WITH IT?!

Discussion in 'PHP' started by Proxyhub, Dec 9, 2007.

  1. #1
    Hey guys.. I am trying to write my first php script that will get text from my mysql database.

    Here is the setup in the DB.

    [​IMG]

    Here is the code.

    
    <?php
    
    $dbh=mysql_connect ("localhost", "proxyhub_a", "a") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("proxyhub_emobands");
    $data = mysql_query("SELECT * FROM band")
    or die(mysql_error());
    $info = mysql_fetch_array( $data );
    Print "<b>Band:</b> ".$info['Band1'] . " ";
    
    ?>
    
    Code (markup):
    I have it uploaded on http://www.demster.info As you can see, it just displays "Band:". What is wrong here?

    Thanks
     
    Proxyhub, Dec 9, 2007 IP
  2. drunnells

    drunnells Peon

    Messages:
    79
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your code actually worked for me.. can you paste part of a mysqldump of the band table that includes the CREATE TABLE and a couple INSERTs? Maybe its something weird with the data?
     
    drunnells, Dec 9, 2007 IP
  3. Proxyhub

    Proxyhub Peon

    Messages:
    909
    Likes Received:
    91
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Im a complete noob at PHP. Is this what you're looking for?

    
    -- Table structure for table `band`
    --
    
    CREATE TABLE `band` (
      `Band1` varchar(250) NOT NULL default 'Linkin Park'
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `band`
    --
    
    Code (markup):
     
    Proxyhub, Dec 9, 2007 IP
  4. YIAM

    YIAM Notable Member

    Messages:
    2,480
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #4
    
    $dbh=mysql_connect ("localhost", "proxyhub_a", "a") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("proxyhub_emobands");
    $data = mysql_query("SELECT * FROM band");
    while($info = mysql_fetch_array($data)){
    Print "<b>Band:</b> ".$info['Band1'] . " ";
    }
    
    PHP:
     
    YIAM, Dec 9, 2007 IP
    Proxyhub likes this.
  5. Proxyhub

    Proxyhub Peon

    Messages:
    909
    Likes Received:
    91
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Get an error.. see @ www.demster.info
     
    Proxyhub, Dec 9, 2007 IP
  6. nuketro0p3r

    nuketro0p3r Peon

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i don't understand :$
    the script seems to work fine
    i got this when i opened your page "Band: Linkin Park"..?
     
    nuketro0p3r, Dec 10, 2007 IP
  7. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I get "Band: Linkin Park" too.
     
    Gawk, Dec 10, 2007 IP
  8. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hold down the CTRL button and click refresh to force your cache to get the latest version of the page.
     
    Gawk, Dec 10, 2007 IP
  9. Proxyhub

    Proxyhub Peon

    Messages:
    909
    Likes Received:
    91
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks for the reply Gawk, but the site already works. :D
     
    Proxyhub, Dec 10, 2007 IP
  10. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Glad it's working, what turned out to be the problem?
     
    Gawk, Dec 10, 2007 IP