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. 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
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?
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):
$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:
i don't understand :$ the script seems to work fine i got this when i opened your page "Band: Linkin Park"..?
Hold down the CTRL button and click refresh to force your cache to get the latest version of the page.