ericburnard Posted December 8, 2007 Share Posted December 8, 2007 Hey i havnt used php or any language for a good few years now, ive decided to get back into it again. Ive set up a sql database and tried to work out the php code to get the entries out of the table (code below) but im just getting these messages - http://ericburnard.freehostia.com/db.php <?php $link = mysql_connect('mysql2.freehostia.com', '*******', '*********'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; $link or die ("Problem connecting to DataBase"); $query = "SELECT * FROM `Blog`"; $result = mysql_select_db($query); if ($result) { echo "Found these entries in the database:<br><p></p>"; while ($r = mysql_fetch_array($result)) { $date = $r["date"]; $subject = $r["subject"]; $blog = $r["blog"]; $id = $r["id"]; echo "<tr> <td>$id</td> <td>$date</td> <td>$subject</td> <td>$blog</td> </tr>"; } echo "</table>"; } else { echo "No data."; } ?> What am i doing wrong??? Cheers xxxxx Link to comment https://forums.phpfreaks.com/topic/80768-confussed/ Share on other sites More sharing options...
wsantos Posted December 8, 2007 Share Posted December 8, 2007 Try this... if (!$link)?die('Could not connect: ' . mysql_error()):echo 'Connected successfully'; Link to comment https://forums.phpfreaks.com/topic/80768-confussed/#findComment-409679 Share on other sites More sharing options...
ericburnard Posted December 8, 2007 Author Share Posted December 8, 2007 I had to change it to this because ther were some errors - if (!$link) die('Could not connect: ' . mysql_error()); echo 'Connected successfully'; but still get this http://ericburnard.freehostia.com/db.php Link to comment https://forums.phpfreaks.com/topic/80768-confussed/#findComment-409700 Share on other sites More sharing options...
ericburnard Posted December 8, 2007 Author Share Posted December 8, 2007 I had to change it to this because ther were some errors - if (!$link) die('Could not connect: ' . mysql_error()); echo 'Connected successfully'; but still get this http://ericburnard.freehostia.com/db.php Link to comment https://forums.phpfreaks.com/topic/80768-confussed/#findComment-409703 Share on other sites More sharing options...
shivarules Posted December 11, 2007 Share Posted December 11, 2007 Dude don worry I wil help u in this case......... First thing u have not selected database properly second u have not used mysql function correctly here it is mysql_select_db('samples', $link); ********** $link or die ("Problem connecting to DataBase"); $query = "SELECT * FROM `Blog`"; $result = mysql_query($query); ********** only the ********** thing you have to change in your code thats it. and open table na echo"<table>"; ********** while ($r = mysql_fetch_array($result)) { if u still face problem feel free to mail me @ [email protected] by the way u r welcome na........ Link to comment https://forums.phpfreaks.com/topic/80768-confussed/#findComment-411740 Share on other sites More sharing options...
shivarules Posted December 11, 2007 Share Posted December 11, 2007 I forgot to tel you use your Database mysql_select_db('samples', $link); samples="your Database"; ******* Cheers Link to comment https://forums.phpfreaks.com/topic/80768-confussed/#findComment-411748 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.