2014-09-24 57 views
-2

我是如此新的PHP/MySQL。數據庫中的日期進來10位數

我做這個教程在線:

會員區系統在PHP的MySQL - 成員的用戶系統區域日誌標誌

http://www.webestools.com/scripts_tutorials-code-source-14-members-area-system-in-php-mysql-members-users-system-area-log-sign.html

到目前爲止一切正常,除了日期。

日期(signup_date列)以奇怪的方式出現在數據庫中。我該如何修復?

ID:1 用戶名名稱:myusername 密碼:HelloWorld的 電子郵件名稱:myusername 頭像:myavatar signup_date:1411562966

非常感謝你的幫助

這是我的MySQL表的代碼:

CREATE TABLE IF NOT EXISTS `users` (

id BIGINT(20)NOT NULL, username VARCHAR(255)NOT NULL, password VARCHAR(255)NOT NULL, email VARCHAR(255)NOT NULL, avatar文本NOT NULL, signup_date時間戳NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )ENGINE = MyISAM DEFAULT CHARSET = utf8;

這是sign_up.php網頁,我想我必須修改日期:

<?php 
include('config.php'); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     <link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" /> 
     <title>Sign up</title> 
    </head> 
    <body> 
     <div class="header"> 
       <a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Members Area" /></a> 
      </div> 
<?php 
//We check if the form has been sent 
if(isset($_POST['username'], $_POST['password'], $_POST['passverif'], $_POST['email'], $_POST['avatar']) and $_POST['username']!='') 
{ 
     //We remove slashes depending on the configuration 
     if(get_magic_quotes_gpc()) 
     { 
       $_POST['username'] = stripslashes($_POST['username']); 
       $_POST['password'] = stripslashes($_POST['password']); 
       $_POST['passverif'] = stripslashes($_POST['passverif']); 
       $_POST['email'] = stripslashes($_POST['email']); 
       $_POST['avatar'] = stripslashes($_POST['avatar']); 
     } 
     //We check if the two passwords are identical 
     if($_POST['password']==$_POST['passverif']) 
     { 
       //We check if the password has 6 or more characters 
       if(strlen($_POST['password'])>=6) 
       { 
         //We check if the email form is valid 
         if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email'])) 
         { 
           //We protect the variables 
           $username = mysql_real_escape_string($_POST['username']); 
           $password = mysql_real_escape_string($_POST['password']); 
           $email = mysql_real_escape_string($_POST['email']); 
           $avatar = mysql_real_escape_string($_POST['avatar']); 
           //We check if there is no other user using the same username 
           $dn = mysql_num_rows(mysql_query('select id from users where username="'.$username.'"')); 
           if($dn==0) 
           { 
             //We count the number of users to give an ID to this one 
             $dn2 = mysql_num_rows(mysql_query('select id from users')); 
             $id = $dn2+1; 
             //We save the informations to the databse 
             if(mysql_query('insert into users(id, username, password, email, avatar, signup_date) values ('.$id.', "'.$username.'", "'.$password.'", "'.$email.'", "'.$avatar.'", "'.time().'")')) 
             { 
               //We dont display the form 
               $form = false; 
?> 
<div class="message">You have successfuly been signed up. You can log in.<br /> 
<a href="connexion.php">Log in</a></div> 
<?php 
             } 
             else 
             { 
               //Otherwise, we say that an error occured 
               $form = true; 
               $message = 'An error occurred while signing up.'; 
             } 
           } 
           else 
           { 
             //Otherwise, we say the username is not available 
             $form = true; 
             $message = 'The username you want to use is not available, please choose another one.'; 
           } 
         } 
         else 
         { 
           //Otherwise, we say the email is not valid 
           $form = true; 
           $message = 'The email you entered is not valid.'; 
         } 
       } 
       else 
       { 
         //Otherwise, we say the password is too short 
         $form = true; 
         $message = 'Your password must contain at least 6 characters.'; 
       } 
     } 
     else 
     { 
       //Otherwise, we say the passwords are not identical 
       $form = true; 
       $message = 'The passwords you entered are not identical.'; 
     } 
} 
else 
{ 
     $form = true; 
} 
if($form) 
{ 
     //We display a message if necessary 
     if(isset($message)) 
     { 
       echo '<div class="message">'.$message.'</div>'; 
     } 
     //We display the form 
?> 
<div class="content"> 
    <form action="sign_up.php" method="post"> 
     Please fill the following form to sign up:<br /> 
     <div class="center"> 
      <label for="username">Username</label><input type="text" name="username" value="<?php if(isset($_POST['username'])){echo htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');} ?>" /><br /> 
      <label for="password">Password<span class="small">(6 characters min.)</span></label><input type="password" name="password" /><br /> 
      <label for="passverif">Password<span class="small">(verification)</span></label><input type="password" name="passverif" /><br /> 
      <label for="email">Email</label><input type="text" name="email" value="<?php if(isset($_POST['email'])){echo htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8');} ?>" /><br /> 
      <label for="avatar">Avatar<span class="small">(optional)</span></label><input type="text" name="avatar" value="<?php if(isset($_POST['avatar'])){echo htmlentities($_POST['avatar'], ENT_QUOTES, 'UTF-8');} ?>" /><br /> 
      <input type="submit" value="Sign up" /> 
       </div> 
    </form> 
</div> 
<?php 
} 
?> 
       <div class="foot"><a href="<?php echo $url_home; ?>">Go Home</a> - <a href="http://www.webestools.com/">Webestools</a></div> 
     </body> 
</html> 
+0

您應該'signup_date'改爲'datetime'數據類型和插入查詢使用'日期( 「YMD H:I:S」)'或mysql函數'now()'而不是'time()'。這將使您在稍後需要執行的查詢方面更好,而無需將時間戳記來回更改。 – 2014-09-24 13:04:46

+0

謝謝。它的工作原理;-)非常感謝。 – user2823725 2014-09-26 00:50:45

回答

1

這是一個Unix風格的時間戳(又名Epoch time),並表示日期星期三,2014年9月24日格林威治標準時間12:49:26它是通過計算1970年1月1日午夜以來的秒數來計算的。

在MySQL中有幾種不同的方法可以represent dates,而不是隻存儲一個int。

0

更改註冊日期

signup_date時間戳NOT NULL

+0

我剛剛做了,現在日期如下: signup_date:0000-00-00 00:00:00 – user2823725 2014-09-24 13:09:49

+0

保存另一個數據。日期將採用以下格式:年,月,日,小時:分鐘:秒yyyy-mm-dd h:m:s – Olalekan 2014-09-24 13:12:22

+0

如果不起作用,請粘貼您用於保存表單值的php代碼。 – Olalekan 2014-09-24 13:16:16