2016-10-22 43 views
1

我想以荷蘭文格式在MySQL中輸入日期。現在他給我的標準格式。我是否需要在輸出列表或插入文件中更改它?將日期轉換爲荷蘭文格式

這是我的插入代碼:

<?php 
session_start(); 


include '../dbh.php'; 

$costname = $_POST['costname']; 
$category = $_POST['category']; 
$subcategory = $_POST['subcategory']; 
$price = $_POST['price']; 
$info = $_POST['info']; 
$costdate = $_POST['costdate']->format("d-m-Y H:i:s"); 
$iduser = $_SESSION['id']; 

if(empty($costname)) { 
    header("Location: ../dashboard.php?error=emptycostname"); 
    exit(); 
} 

if(empty($category)) { 
    header("Location: ../dashboard.php?error=emptycatergory"); 
    exit(); 
} 

if(empty($subcategory)) { 
    header("Location: ../dashboard.php?error=emptysubcatergory"); 
    exit(); 
} 

if(empty($price)) { 
    header("Location: ../dashboard.php?error=emptyprice"); 
    exit(); 
} 

if(empty($info)) { 
    header("Location: ../dashboard.php?error=emptyinfo"); 
    exit(); 
} 

else { 
    $sql = "INSERT INTO costs (costname, category, subcategory, price, info, userid, costdate) 
    VALUES ('$costname', '$category', '$subcategory', '$price', '$info', '$iduser', '$costdate')"; 

    $result = mysqli_query($conn, $sql); 

    header("Location: ../dashboard.php"); 

} 

現在我需要顯示它的名單上,我有此代碼從數據庫獲取它:

<?php 
include('includes/sessionstart.php'); 
include 'dbh.php'; 
if (isset($_SESSION['id'])) { ?> 


    <?php include 'includes/header.php'; 




    // costslist define mysql 
    $sql_costs = "SELECT * FROM costs WHERE userid='".$_SESSION['id']."'"; 
    $result_costs = mysqli_query($conn, $sql_costs); 




    $costname = $row_costs['costname']; 





    <div class="content"> 
     <div class="container-fluid"> 
      <div class="row"> 
       <div class="col-md-12"> 
        <div class="card"> 
         <div class="header"> 
          <h4 class="title">Wonen</h4> 
          <p class="category">Kosten gespendeerd aan uw woning.</p> 
         </div> 
         <div class="content table-responsive table-full-width"> 
          <table class="table table-hover table-striped"> 
           <thead> 
                    <th>Subcategorie</th> 
                    <th>Kostnaam</th> 
                    <th>Kostprijs</th> 
                    <th>Extra info</th> 
                    <th>Datum toegevoegd</th> 

           </thead> 
           <tbody> 

                      <?php 
                      while($row = $result_costs->fetch_assoc()) { ?> 
                       <tr> 
                        <td><?php echo $row['subcategory']; ?></td> 
                        <td><?php echo $row['costname']; ?></td> 
                        <td><?php echo $row['price']; ?></td> 
                        <td><?php echo $row['info']; ?></td> 
                        <td><?php echo $row['costdate']; ?></td> 

                        </tr> 
                      <?php } ?> 
           </tbody> 
          </table> 

         </div> 
        </div> 
       </div> 
+0

請注意,你的代碼容易受到SQL注入式攻擊,把你的服務器存在風險。閱讀更多關於如何安全地做到這一點:https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php –

回答