Jump to content


Photo

not displaying info from database?


  • Please log in to reply
5 replies to this topic

#1 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 17 June 2006 - 08:06 AM

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?

<?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>
';

?>





#2 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 17 June 2006 - 08:38 AM

because on each while() loop you're replacing the data, why is the echo outside the loop?

"/* ******** SELECT ROWS AND SET THEM AS VARIABLES FOR LATER USE ******** */"

You\re just overwriting the variables
z..z..z..z..z..z..z..z..

#3 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 17 June 2006 - 02:02 PM

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

#4 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 17 June 2006 - 02:20 PM

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

current updatec 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 ******** */
}
}

?>



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

#5 aebstract

aebstract
  • Members
  • PipPipPip
  • Advanced Member
  • 1,105 posts

Posted 17 June 2006 - 02:26 PM

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.

There is an area of the mind that could be called unsane, beyond sanity, and yet
not insane. Think of a circle with a fine split in it. At one end there's
insanity. You go around the circle to sanity, and on the other end of the
circle, close to insanity, but not insanity, is unsanity.


#6 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 17 June 2006 - 02:32 PM

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

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users