Jump to content

not displaying info from database?


localhost

Recommended Posts

contact form into admin panel, it does insert it into the database i checked in phpmyadmin, just cant get it to select, it echos $id instead of the actual id, and $name instead of the actual name, some help?

[code]
<?php

/* ******** INCLUDE DB CONNECTION AND SET VARIABLES ******** */
include('../includes/connect.php');

$date = date('m/d/Y');

/* ******** SELECT DATA TO DISPLAY MESSAGES FROM TODAY ******** */
$query = "SELECT * FROM `contact` WHERE `sentdate` = '$date' ORDER BY id DESC";
$result = mysql_query($query) or die('Could not select messages from today');
while ($rows = mysql_fetch_array($result, MYSQL_ASSOC))
        {

/* ******** SELECT ROWS AND SET THEM AS VARIABLES FOR LATER USE ******** */
$id = $rows['id'];
$name = $rows['name'];
$email = $rows['email'];
$subject = $rows['subject'];
$message = $rows['messages'];
$ipaddress = $rows['ipaddress'];

}

/* ******** DISPLAY THE DATA SELECTED IN A PROPER MANNER ******** */
echo '
Messages sent to you today, $date<br>
Message ID number $id<Br>
Claimed to be from: $name<BR>
Acclaimed eMail: $email<BR>
Subject: $subject<Br>
Message:<Br>
$message<Br>

Users Logged IP: <a href=http://$ipaddress>$ipaddress</a><Br>
______________________________________________
<Br>
<Br>
';

/* ******** SELECT DATA TO DISPLAY MESSAGES RECEIVED IN TOTAL ******** */
$query2 = "SELECT * FROM `contact` ORDER BY id DESC";
$result2 = mysql_query($query2) or die('Could not select total messages from database');

/* ******** DISPLAY THE DATA SELECTED IN A PROPER MANNER ******** */
echo '
Total Messages Sent<br>
Message ID number $id<Br>
Claimed to be from: $name<Br>
Acclaimed eMail: $email<Br>
Subject: $subject<Br>
Message:<br>
$message<Br>

Users Logged IP: <A href=http://$ipaddress>$ipaddress</a><br>
______________________________________________
<br>
<Br>
';

?>



[/code]
Link to comment
https://forums.phpfreaks.com/topic/12224-not-displaying-info-from-database/
Share on other sites

so i took out the comment...but what else should be in the loop?

current updatec code:
[code]<?php

/*======================================================================*\
|| #################################################################### ||
|| # .Omega Community System 2006 version 0.6                         # ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2006 dotOmega                                         # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- DOTOMEGA IS NOT FREE SOFTWARE ----------------- # ||
|| #         http://dotomega.com | http://licence.dotomega.com        # ||
|| #################################################################### ||
\*======================================================================*/

/* ******** INCLUDE DB CONNECTION AND SET VARIABLES ******** */
include('../includes/connect.php');

$date = date('m/d/Y');

/* ******** SELECT DATA TO DISPLAY MESSAGES FROM TODAY ******** */
$query = "SELECT * FROM `contact` WHERE `sentdate` = '$date' ORDER BY id DESC";
$result = mysql_query($query) or die('Could not select messages from today');
while ($rows = mysql_fetch_array($result, MYSQL_ASSOC))
        {

$id = $rows['id'];
$name = $rows['name'];
$email = $rows['email'];
$subject = $rows['subject'];
$message = $rows['messages'];
$ipaddress = $rows['ipaddress'];

print "
Messages sent to you today, $date<br>
";

/* ******** IN THE CASE THAT NO MESSAGES WERE SENT TODAY ******** */
$numrows = mysql_num_rows($result);

if($numrows<1) {
echo ' No Messages received today ';
} else {
/* ******** DISPLAY THE DATA SELECTED IN A PROPER MANNER ******** */
echo '
Message ID number $id<Br>
Claimed to be from: $name<BR>
Acclaimed eMail: $email<BR>
Subject: $subject<Br>
Message:<Br>
$message<Br>

Users Logged IP: <a href=http://$ipaddress>$ipaddress</a><Br>

<Br>
<Br>
';

print "
_________________________________________________________________
<Br>
Total Messages Sent<br>
";

/* ******** SELECT DATA TO DISPLAY MESSAGES RECEIVED IN TOTAL ******** */
$query2 = "SELECT * FROM `contact` ORDER BY id DESC";
$result2 = mysql_query($query2) or die('Could not select total messages from database');

/* ******** DISPLAY THE DATA SELECTED IN A PROPER MANNER ******** */
echo '
Message ID number $id<Br>
Claimed to be from: $name<Br>
Acclaimed eMail: $email<Br>
Subject: $subject<Br>
Message:<br>
$message<Br>

Users Logged IP: <A href=http://$ipaddress>$ipaddress</a><br>
______________________________________________
<br>
<Br>
';

/* ******** END ALL IF STATEMENTS AND FINISH THE SCRIPT ******** */
}
}

?>
[/code]



so i took out the comment...but what else should be in the loop?
when you echo variables, remember theres two ways to echo.. as far as I know

echo '';
and
echo "";

the difference in the quotation marks.
Single quotes will enter a whatever is in them exactly how it is seen, leaving your variable as $id and whatnot. If you use double quotes, it puts it in as the actual id and not $id.


Edit: to clarify sorry,

Single Quotes: Treated Literally
Double Quotes: Extrapolated - a variable's name is replaced with its value.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.