Reply
php date error
Old 10-01-2006, 04:15 AM php date error
evans123's Avatar
Ultra Talker

Posts: 271
umm..... this scrip uploads names to a database with the kword and time but when it inserts the time it gets 0000-00-00 00:00:00 i dunno whats wrong also when i sort it on date it doesnt work and takes the lowest date even tho ders another one that has been updated later.

PHP Code:
<?php session_register("loggedin");
?>
<?php
if ($action == 'addname')
{
$name   $_POST['name'];
$keywords  $_POST['kwords'];
$time date('YYYY-MM-DD HH:MM:SS');
@
mysql_query ("INSERT INTO msn_names (ID, string, kwords, username, time) VALUES ('', '$name','$keywords','$loggedin','$time')");;
$done "You Have Successfully Suggested A Name <br>";
}
?>
<?php
$result 
mysql_query("SELECT * FROM msn_names where username = '$loggedin'");
$num_rows mysql_num_rows($result);
$outof mysql_query("SELECT * FROM msn_names");
$num_rows2 mysql_num_rows($outof);
?>
<td valign="top">
<table width="500"  border="0" cellpadding="0" cellspacing="0" class="greyBox"> 
<tr><td><div align="left" class="intro"> 
          <h1><font color="#3888CA">Upload Your Own <font color="#ffa200">Weird 
            Names</font></font></h1> 
          <p class="normalText"><strong>NEW!!</strong>!- Do you want to upload 
            your own name to our name generator. Well if so think of a name and 
            type it in the box along with a keyword and press ok.</p>
          <p class="normalText">Before You upload your weird name make sure that 
            your name is found below otherwise it won't log your points. Enter 
            your msn name and a key word to go with it and then click submit. 
            If any name or keyword is found to be empty it will get deleted straight 
            away and you will recieve no points for it.</p>
          <p class="normalText">Stats Will be Updated For User: <?php echo "<b>$loggedin</b>" ?> 
          </p>
          <p class="normalText"><strong>Quick Stats</strong></p>
          <p class="normalText"><?php If ($num_rows == "")
  {
  echo 
"<b><font color = '#ff0000'>Error:</b></font> No Stats Generated.<br>Either your login name isnt recognised or you haven't uploaded yet.";
  } 
  else
  
$upname mysql_query("SELECT * FROM `msn_names` WHERE `username` = '$loggedin' ORDER BY `time`, `id` DESC  LIMIT 1");
while(
$row mysql_fetch_array($upname))
$upname2 "" $row['string'] . "";
$upname3 "" $row['time'] . "";
     echo 
"You have suggested $num_rows names out of a total of $num_rows2 names.<br> <font color='#FFCC33'><b>Ranked #1</b></font> For Names Uploaded.<br>
  <br>You last uploaded <font color='#FF0000'>$upname2</font> to the name generator at $upname3.
  </p>"
;
                     
?>
          <form action="mem_name_generator.php?action=addname" method="post">
            <p class="normalText"><strong>Add Your Weird Names Here</strong></p>
            <table width="76%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="22%"><p class="normalText">Name:</p></td>
                <td width="78%"><input name="name" type="text" id="name"></td>
              </tr>
              <tr> 
                <td><p class="normalText">Key Word:</p></td>
                <td><input name="kwords" type="text" id="kwords" /></td>
              </tr>
            </table>
            <p class="normalText"><?php echo "<p class='normalText'>$done</p>"?></p>
   <p><input type="submit" name="submit" value="Add Name" /></p>
                        </form>
          
                  <p><?php echo $last?></p></div>
        <p class="normalText"><?php If ($num_rows >= "5")
  {
    if (
$action == 'lastfive')
{
$lastfivedp mysql_query("SELECT * FROM `msn_names` WHERE `username` = '$loggedin' ORDER BY `time`, `id` ASC  LIMIT 5");
while(
$row mysql_fetch_array($lastfivedp))
  {
  echo 
"<b>" $row['time'] . "</b>";
  echo 
"" $row['string'] . "";
  echo 
"<br>";
  echo 
"<br>";
  }
  }
   echo 
"Want to view your last five names that you've added to the name generator 
        <a href='http://www.*******.com/members_content/mem_name_generator.php?action=lastfive'>click 
        here</a> to do so.</p>"
;
  }
  
?>
        <div style="margin:auto;width:100px;"><table width="83%" style="border-collapse: collapse;padding:0;width:100%;">
                     </table>
                  
                 
        </div>
  
 
</td></tr></table>
            </td>
       <td valign="top" class="SideBox">
__________________
SoldierExteme.com - Free MMORPG - sign-up today!
Backthebulls.com - Free online games (mad_willsy's)
Msnextra.co.uk - Msn Items
evans123 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 10-01-2006, 01:28 PM Re: php date error
Webmaster Talker

Posts: 589
Location: Atlanta, GA
$time = date('y-m-d d:m:s');

I think thats what you want.
neorunner is offline
Reply With Quote
View Public Profile
 
Old 10-01-2006, 02:00 PM Re: php date error
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Wireless Audio
Posts: 2,322
Name: Keith Marshall
Location: West Hartford, CT
Quote:
Originally Posted by neorunner View Post
$time = date('y-m-d d:m:s');

I think thats what you want.
Actually for the format: YYYY-MM-DD HH:MM:SS you use:

date('Y-m-d H:i:s');
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 10-01-2006, 03:24 PM Re: php date error
evans123's Avatar
Ultra Talker

Posts: 271
ill give it a try!
__________________
SoldierExteme.com - Free MMORPG - sign-up today!
Backthebulls.com - Free online games (mad_willsy's)
Msnextra.co.uk - Msn Items
evans123 is offline
Reply With Quote
View Public Profile
 
Old 10-01-2006, 03:26 PM Re: php date error
evans123's Avatar
Ultra Talker

Posts: 271
wicked works cheers mgraphic talk thingy coming ur way
__________________
SoldierExteme.com - Free MMORPG - sign-up today!
Backthebulls.com - Free online games (mad_willsy's)
Msnextra.co.uk - Msn Items
evans123 is offline
Reply With Quote
View Public Profile
 
Old 10-02-2006, 02:26 AM Re: php date error
evans123's Avatar
Ultra Talker

Posts: 271
i got da date thingy to work yesterday but now when go onto it i get

You last uploaded [*$Your Name$*:P] to the name generator on the 1159767645.

1159... as the date heres the script.

PHP Code:
<?php session_register("loggedin");
?>
<?php
if ($action == 'addname')
{
$name2 $_POST['name'];
}
{
if(!empty(
$name2))
{
$name   $_POST['name'];
$keywords  $_POST['kwords'];
$time date('Y-m-d H:i:s');
$sql mysql_query ("INSERT INTO msn_names (ID, string, kwords, username, time) VALUES ('', '$name','$keywords','$loggedin','$time')");
mysql_query($sql);
$done "<p class='normalText'>You Have Successfully Suggested A Name.</p>";
} else 
$noname "<p class='normalText'No Name Entered</p>";
}
?>
<?php
$result 
mysql_query("SELECT * FROM msn_names where username = '$loggedin'");
$num_rows mysql_num_rows($result);
$outof mysql_query("SELECT * FROM msn_names");
$num_rows2 mysql_num_rows($outof);
$latest mysql_query("SELECT * FROM msn_names order by `id`");
while(
$row mysql_fetch_array($latest))
$latest2 "" $row['string'] . "";
$latest4 mysql_query("SELECT * FROM msn_names order by `id`");
while(
$row mysql_fetch_array($latest4))
$latest3 "" $row['username'] . "";
$query "SELECT * FROM msn_settings";
$result3 mysql_query($query) or die(mysql_error());
while (list (
$pics$name$shout) = mysql_fetch_row($result3))
$totalpoints $num_rows2 $name;
?>
<td valign="top">
<table width="500"  border="0" cellpadding="0" cellspacing="0" class="greyBox"> 
<tr><td><div align="left" class="intro"> 
          <h1><font color="#3888CA">Upload Your Own <font color="#ffa200">Weird 
            Names</font></font></h1> 
          <p class="normalText"><strong>NEW!!!</strong>- Do you want to upload 
            your own name to our name generator. Well if so think of a name and 
            type it in the box along with a keyword and press ok.</p>
          <p class="normalText">Before You upload your weird name make sure that 
            your name is found below otherwise it won't log your points. Enter 
            your msn name and a key word to go with it and then click submit. 
            If any name or keyword is found to be empty it will get deleted straight 
            away and you will recieve no points for it.</p>
          <p class="normalText">Stats Will be Updated For User: <?php echo "<b>$loggedin</b>" ?> 
          </p>
          <p class="normalText"><strong>Name Generator Stats</strong></p>
          <p class="normalText"><strong>Last Name Added: </strong><?php echo "<font color='#FF0000'>[$latest2]</font> added by $latest3 on the $time.<br>"?>
            <strong>Total Points From Suggested Names: </strong><?php echo $totalpoints ?></p>
          <p class="normalText"><strong>Quick Stats<br>
            </strong> 
            <?php If ($num_rows == "")
  {
  echo 
"<br><b><font color = '#ff0000'>Error:</b></font> No Stats Were Found For User $loggedin.<br>-Either your login name isnt recognised or you haven't uploaded yet.";
  } 
$upname mysql_query("SELECT * FROM `msn_names` WHERE `username` = '$loggedin' ORDER BY `id` DESC  LIMIT 1");
while(
$row mysql_fetch_array($upname))
$upname2 "" $row['string'] . "";
$upname3 "" $row['time'] . "";
$result3 mysql_query($query) or die(mysql_error());
while (list (
$pics$name$shout) = mysql_fetch_row($result3))
$points $num_rows $name;
$pointsname 100 $totalpoints $points;
$pointsname2 round($pointsname1); 
    echo 
"<br><b>Stat: </b>You have suggested $num_rows names out of a total of $num_rows2 names.<br></b><b>You've added:</b> $pointsname2 % of the names added.<br> <b>Rank: </b>#1 For $num_rows Names Uploaded.<br>
  <br>You last uploaded <font color='#FF0000'>[$upname2]</font> to the name generator on the $time.</p>"
;
       
?>
          </p>
          <form action="mem_name_generator.php?action=addname" method="post">
            <p class="normalText"><strong>Add Your Weird Names Here</strong></p>
            <table width="76%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="22%"><p class="normalText">Name:</p></td>
                <td width="78%"><input name="name" type="text" id="name" value="Enter Name Here"></td>
              </tr>
              <tr> 
                <td><p class="normalText">Key Word:</p></td>
                <td><input name="kwords" type="text" id="kwords" /></td>
              </tr>
            </table>
            <p class="normalText"><?php echo "<p class='normalText'>$last</p>";
echo 
"<p class='normalText'>$noname</p>"?></p>
   <p><input type="submit" name="submit" value="Add Name" /></p>
                        </form>
          
                  <p><?php echo $done?></p></div>
        <p class="normalText"><?php If ($num_rows >= "5")
  {
  echo 
"Want to view your last five names that you've added to the name generator 
        <a href='http://www.******.com/members_content/mem_name_generator.php?action=lastfive'>click 
        here</a> to do so.</p>"

  {
   if (
$action == 'lastfive')
   {
  
$lastfivedp mysql_query("SELECT * FROM `msn_names` WHERE `username` = '$loggedin' ORDER BY `time`, `id` DESC  LIMIT 5");
while(
$row mysql_fetch_array($lastfivedp))
{
  echo 
"<p class='normalText'>";
  echo 
"<b>Date Added: " $row['time'] . "</b>";
  echo 
"<br>" $row['string'] . "";
  echo 
"<br>";
  echo 
"<br>";
  echo 
"</p>";
  }
  }
  }
  }
  
?>
        <div style="margin:auto;width:100px;"><table width="83%" style="border-collapse: collapse;padding:0;width:100%;">
                     </table>
                  
                 
        </div>
  
 
</td></tr></table>
            </td>
       <td valign="top" class="SideBox">
__________________
SoldierExteme.com - Free MMORPG - sign-up today!
Backthebulls.com - Free online games (mad_willsy's)
Msnextra.co.uk - Msn Items
evans123 is offline
Reply With Quote
View Public Profile
 
Old 10-02-2006, 02:40 AM Re: php date error
evans123's Avatar
Ultra Talker

Posts: 271
problem when i order by dates it takes the 1st of the month as the highest and the 2nd as the lowest and so on?
__________________
SoldierExteme.com - Free MMORPG - sign-up today!
Backthebulls.com - Free online games (mad_willsy's)
Msnextra.co.uk - Msn Items
evans123 is offline
Reply With Quote
View Public Profile
 
Old 10-02-2006, 07:28 PM Re: php date error
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Wireless Audio
Posts: 2,322
Name: Keith Marshall
Location: West Hartford, CT
The date will return a unix timestamp so you will need to format it using the date function. If you want to order the results in reverse, just use ORDER BY dates DESC
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 10-03-2006, 10:45 AM Re: php date error
evans123's Avatar
Ultra Talker

Posts: 271
how do i do an if to say if $time2 = date('Y-m-d H:i:s'); is = to todays date?
__________________
SoldierExteme.com - Free MMORPG - sign-up today!
Backthebulls.com - Free online games (mad_willsy's)
Msnextra.co.uk - Msn Items

Last edited by evans123 : 10-03-2006 at 02:25 PM.
evans123 is offline
Reply With Quote
View Public Profile
 
Old 10-04-2006, 03:54 AM Re: php date error
vectorialpx's Avatar
Super Talker

Posts: 128
Name: irimia octavian
Location: Romania
did u ese NOW() ?
@
mysql_query ("INSERT INTO msn_names (ID, string, kwords, username, time) VALUES ('', '$name','$keywords', '$loggedin', NOW()");
__________________
my photos, my website, creation lab
vectorial pixel web services :: and, sorry for my English !
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 10-04-2006, 11:14 AM Re: php date error
evans123's Avatar
Ultra Talker

Posts: 271
no dats not what i want
i want an if to say if $time = NOW!
__________________
SoldierExteme.com - Free MMORPG - sign-up today!
Backthebulls.com - Free online games (mad_willsy's)
Msnextra.co.uk - Msn Items
evans123 is offline
Reply With Quote
View Public Profile
 
Old 10-05-2006, 02:07 AM Re: php date error
jito's Avatar
MY LIFE IS 'i' LIFE

Posts: 551
Name: surajit ray
Location: inside the heart of my friends
date("Y-m-d") always returns the current date!
__________________
Think+, work +, but not HIV + :)
jito is offline
Reply With Quote
View Public Profile
 
Old 10-05-2006, 07:45 AM Re: php date error
vectorialpx's Avatar
Super Talker

Posts: 128
Name: irimia octavian
Location: Romania
jito is right ...

date shows you server-s date/time...

http://ro2.php.net/manual/en/function.date.php
http://ro2.php.net/manual/en/function.time.php
__________________
my photos, my website, creation lab
vectorial pixel web services :: and, sorry for my English !
vectorialpx is offline