geting data from the database.

[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.

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]

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

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.

Sponsor our Newsletter | Privacy Policy | Terms of Service