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 Quote Link to comment 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'; Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 @ shivarules@gmail.com by the way u r welcome na........ Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.