Page 1 of 1

mysql_fetch_assoc not echoing date value

Posted: Thu Apr 16, 2009 10:28 am
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?

Re: mysql_fetch_assoc not echoing date value

Posted: Thu Apr 16, 2009 6:21 pm
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

Re: mysql_fetch_assoc not echoing date value

Posted: Thu Apr 16, 2009 9:47 pm
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.

Re: mysql_fetch_assoc not echoing date value

Posted: Fri Apr 17, 2009 8:57 am
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.

Re: mysql_fetch_assoc not echoing date value

Posted: Fri Apr 17, 2009 10:13 am
by anivad
That worked. Thanks!