Vineman Posted December 24, 2006 Share Posted December 24, 2006 I'm having a problem getting info from my MySQL database. It's connecting fine and as far as I can tell it's set up just fine, but it keeps returning that there's no info despite the database having two entries.The value retrieval:[code=php:0]$newsQuery = mysql_query("SELECT * FROM news ORDER BY ID DESC limit 0,1");if($newsQuery == NULL){$title = "No news has been recorded.";}else if($newsQuery != NULL){$n = mysql_fetch_array($newsQuery);$title = $n["title"];$subtitle = $n['subtitle'];$body = $n["body"];}[/code]This is what the database looks like:CREATE TABLE `news` ( `ID` int(6) NOT NULL auto_increment, `IP` varchar(20) NOT NULL default '', `title` varchar(60) NOT NULL default '', `subtitle` varchar(60) NOT NULL default '', `body` text NOT NULL, PRIMARY KEY (`ID`)) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;How it's being used:[code=php:0]<h2><? echo"$title";?></h2><p class="description"><? echo"$subtitle";?></p><p><? echo"$body";?></p>[/code]Help :-\ Link to comment https://forums.phpfreaks.com/topic/31740-solved-phpmysql-problem/ Share on other sites More sharing options...
Barand Posted December 24, 2006 Share Posted December 24, 2006 The first thing to do is check for any errors[code]<?php$newsQuery = mysql_query("SELECT * FROM news ORDER BY ID DESC limit 0,1") or die (mysql_error());?>[/code]and see if that gives any clues Link to comment https://forums.phpfreaks.com/topic/31740-solved-phpmysql-problem/#findComment-147138 Share on other sites More sharing options...
Vineman Posted December 24, 2006 Author Share Posted December 24, 2006 I just realized what it was. I guess I was looking for a hard solution and overlooked the painfully simple :PThanks for the help. Link to comment https://forums.phpfreaks.com/topic/31740-solved-phpmysql-problem/#findComment-147141 Share on other sites More sharing options...
Barand Posted December 24, 2006 Share Posted December 24, 2006 You don't need quotes round variables, only round string literals. But as long as they're double quotes it should be OKmysql_connect ("localhost", $dbUser, $dbPass);mysql_select_db ($dbName); Link to comment https://forums.phpfreaks.com/topic/31740-solved-phpmysql-problem/#findComment-147142 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.