mysql_fetch_assoc not echoing date value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anivad
Forum Commoner
Posts: 80
Joined: Thu Apr 09, 2009 11:16 pm

mysql_fetch_assoc not echoing date value

Post by anivad »

Trying to grab information for a profile page. For some reason the registration date does not get echoed even though the other values all do:

Code: Select all

<?php
 
include 'db.php';
 
$uname = $_SESSION['uname'];
 
$sql = "SELECT * FROM logintest WHERE uname='$uname'";
$result = mysql_query($sql) or die (mysql_error());
$num_rows = mysql_num_rows($result);
 
    if ($result) {
$data = mysql_fetch_assoc($result);
$userid = $data['userid'];
$email = $data['email'];
$regdate = $data['regdate'];        
}
 
else {
error('A database error occured');
}
 
?>
 
<center>
<table border="1">
<tr><td colspan="2" width="600"><font size="4"><? print $uname ?></font></td></tr>
<tr><td><b>User ID #</b></td><td><? print $userid ?></td></tr>
<tr><td><b>E-mail adddress</b></td><td><? print $email ?> <a href="changeemail.htm">(Change)</a></td></tr>
<tr><td><b>Registration date</b></td><td><? print $regdate ?></td></tr>
<tr><td colspan="2"><a href="changepass.htm">Change Password</a></td><td></td></tr>
</table>
 
$regdate appears fine in the MySQl table. In the registration form, it's defined as:

Code: Select all

$date = date("F d, Y");
$time = date("H:i");
$timediff = date("O");
$regdate = $date . ", " . $time . " (GMT" . $timediff . ")";
Could that be part of the problem, or is it something simpler like a typo somewhere?
enoc22
Forum Commoner
Posts: 33
Joined: Wed Apr 01, 2009 12:45 pm

Re: mysql_fetch_assoc not echoing date value

Post by enoc22 »

Hi
I don't see Anywhere in the code you posted where the date would echo out. is the highlighted part the variable thats supposed to contain the date?

Code: Select all

$userid = $data['userid'];
$email = $data['email'];
[b][color=#FF0000]$regdate = $data['regdate'];    [/color][/b]   
}
 
else {
error('A database error occured');
}
Oliver
anivad
Forum Commoner
Posts: 80
Joined: Thu Apr 09, 2009 11:16 pm

Re: mysql_fetch_assoc not echoing date value

Post by anivad »

Yeah, that's the variable.

It gets echoed out on another page, which basically goes:

echo $uname;
echo $userid;
echo $regdate;
echo $email;

And they all appear except for $regdate.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: mysql_fetch_assoc not echoing date value

Post by McInfo »

Use a single call to date() to set $regdate.

Code: Select all

$regdate = date('F d, Y, H:i (\G\M\TO)');
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Mon Jun 14, 2010 2:59 pm, edited 2 times in total.
anivad
Forum Commoner
Posts: 80
Joined: Thu Apr 09, 2009 11:16 pm

Re: mysql_fetch_assoc not echoing date value

Post by anivad »

That worked. Thanks!
Post Reply