# geting data from the database.

**URL:** <https://www.phphelp.com/t/geting-data-from-the-database/10160>\
**Category:** Beginners - Learning PHP\
**Created:** [July 29, 2007, 3:39am UTC](https://www.phphelp.com/t/geting-data-from-the-database/10160 "2007-07-29T03:39:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon\_W](https://www.phphelp.com/letter_avatar_proxy/v4/letter/j/3e96dc/32.png) [@Jon\_W](https://www.phphelp.com/u/Jon_W)\
**Post date:** [July 29, 2007, 3:39am UTC](https://www.phphelp.com/t/geting-data-from-the-database/10160/1 "2007-07-29T03:39:30Z")

</div>

[php]

\<?php // connect to the database. include("config\_mysql.php"); //select table to get info from $query = mysql\_query ("SELECT firstname, lastname, post FROM submittosite ORDER BY id"); or die("Database error. Please contact admin"); while($shout = mysql\_fetch\_array($query)) { echo ".".$shout['post'] ."  
" .$shout['firstname'] ."  
".$shout['lastname']"."; } ?\>

[/php]

Ok, for some reason I can’t seem to get this to display anything from the database. I know I have stuff stored in this table because I submited something into it from my form here. So not to sure what I did wrong there.

---

<div class="post-metadata">

**Author:** ![CTBC](https://www.phphelp.com/letter_avatar_proxy/v4/letter/c/7bcc69/32.png) [@CTBC](https://www.phphelp.com/u/CTBC)\
**Post date:** [July 29, 2007, 1:03pm UTC](https://www.phphelp.com/t/geting-data-from-the-database/10160/2 "2007-07-29T13:03:07Z")

</div>

I think I know the problem but i may be wrong.

Replace  
[php]  
echo “.”.$shout[‘post’] ."  
" .$shout[‘firstname’] ."  
".$shout[‘lastname’]".";  
[/php]

with  
[php]  
echo “.”.$shout[‘post’] ."  
" .$shout[‘firstname’] ."  
".$shout[‘lastname’] . “.”;  
[/php]

---

<div class="post-metadata">

**Author:** ![Jon\_W](https://www.phphelp.com/letter_avatar_proxy/v4/letter/j/3e96dc/32.png) [@Jon\_W](https://www.phphelp.com/u/Jon_W)\
**Post date:** [July 29, 2007, 9:06pm UTC](https://www.phphelp.com/t/geting-data-from-the-database/10160/3 "2007-07-29T21:06:08Z")

</div>

Yes, yes. I got this working story after messing around with it. And actually did a little more then that.

[php]

\<?php include("config\_mysql.php"); $db = mysql\_select\_db("allihil6\_chatmu", $connect); $sql = mysql\_query("SELECT fname, lname, email, post FROM contact ORDER BY id") or die("Database error. Please contact admin"); while($shout = mysql\_fetch\_array($sql)) { if(!empty($shout['email'])) { $link\_start = ""; $link\_end = ""; }else $link\_start = ""; $link\_end = ""; } echo "".$link\_start.$shout['fname'].$link\_end."  
".$shout['lname']."  
".$shout['post']."  

* * *
"; } ?\>[/php]

That code seemed to work nicely. Though didn’t come much use to me as I’m just scripting it for the pratices. I’m moving onto the session function now. This seems to have a bit more to it then others. ![:P]()

---

<div class="post-metadata">

**Author:** ![Ragster00](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/a9adbd/32.png) [@Ragster00](https://www.phphelp.com/u/Ragster00)\
**Post date:** [July 30, 2007, 1:32pm UTC](https://www.phphelp.com/t/geting-data-from-the-database/10160/4 "2007-07-30T13:32:25Z")

</div>

Jon,  
As I stated in a previous post, you need to do some debugging.

When in the development phase you should have on error\_reporting(“E\_ALL”)

At least this way you know php is going to display errors.

Secondly… When executing queries: mysql\_query(“SELECT…”) or die("Error querying for cars. REASON: " . mysql\_error());

Something like that would help to display MySQL errors saving you time trying to figure out what is wrong blindly.
