Jump to content

Help! How do I remove the time in this PHP Script?


stennchau

Recommended Posts

Hi,

 

I am new to PHP and I need help to remove the time (but keep the date).

 

Here is the script. Thank You in advance for your help.

 

<?php

require_once('../config/config.php');

require_once('../config/func.php');

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

      <title>News</title>

      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">

      <link href="../config/style.css" rel="stylesheet" type="text/css">

  </head>

  <script language="JavaScript">

      function check(id)

        {

        if (confirm('Are you sure?'))

            {

            window.location='news.php?action=del&id=' + id;

            }

        }

      function clear_form(form)

        {

        form.elements[0].value='';

        form.elements[1].value='';

        form.text.value='';

        }

  </script>

<body>

<div class="admin">NEWS<?php echo (!empty($_GET['form']) ? ' - ' . $_GET['form'] : ''); ?></div>

<?php

$form=$_GET['form'];

if (auth())

  {

  if (!empty($_GET['action']))

      {

      $action=$_GET['action'];

      if ($action=='add' || ($action=='edit' && strlen($_POST['id'])))

        {

        if (!empty($_POST['tytul']) && !empty($_POST['data']) && !empty($_POST['text']))

            {

            $tytul=str_replace('"', '"', $_POST['tytul']); $data=str_replace(",", "", $_POST['data']); $text=str_replace('"', '"', $_POST['text']);

            if (preg_match("/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/", $data))

              {

              if ($action=='add')

                  $sql="INSERT INTO `news` VALUES ('', '$tytul', '$data', '$text')";

              else

                  {

                  $id=$_POST['id'];

                  $sql="UPDATE `news` SET `tytul`='$tytul', `data`='$data', `tresc`='$text' WHERE `id_news`='$id'";

                  }

              if (mysql_query($sql))

                  {

                  switch_page('news.php?form=' . (($action=='add') ? 'add' : 'edit/delete'), (($action=='add') ? 'Added' : 'Updated') . ' news!');

                  }

              else

                  error('Error in SQL query! MySQL: ' . mysql_error() . '

<a href="javascript:history.go(-1)">return[/url]');

              }

            else

              error('Wrong date format (yyyy-mm-dd, hh:mm:ss)! <a href="javascript:history.go(-1)">return[/url]');

            }

        else

            error('<div class="error">Fill all fields! <a href="javascript:history.go(-1)">return[/url]');

        }

      elseif($action=='del' && strlen($_GET['id']))

        {

        $id=$_GET['id'];

        if(mysql_query("DELETE FROM `news` WHERE `id_news`='$id'"))

            {

            switch_page('news.php?form=edit/delete', 'Deleted news from database');

            }

        else

            error('Error in SQL query! MySQL: ' . mysql_error() . '

<a href="javascript:history.go(-1)">return[/url]');

        }

      }

  else

      {

      if ($form=='add')

        {

      ?>

        <table style="margin:10px" width="90%">

        <?php

            if (($_GET['mode']=='edit') && (strlen($_GET['id'])))

              {

              $id&=$_GET['id'];

              if($result=mysql_query("SELECT tytul, data, tresc FROM news WHERE `id_news`='$id'"))

                  {

                  $t=@mysql_result($result, 0, 0);

                  $d=@mysql_result($result, 0, 1);

                  $text=@mysql_result($result, 0, 2);

                  $read=false;

                  if (strlen($t) && strlen($d) && strlen($text))

                    $read=true;

                  else

                    error('Error while trying to read data. Cannot display information!');

                  }

              else

                  error('Error in SQL query! MySQL: ' . mysql_error() . '

Cannot display data!');

              }

        ?>

            <form method="POST" style="margin: 0px" name="post" action="news.php?action=<?php echo (($read && ($_GET['mode']=='edit')) ? 'edit' : 'add'); ?>">

              <?php if($read && ($_GET['mode']=='edit')) echo '<input type="hidden" name="id" value="'.$id .'">'; ?>

              <tr>

                  <td>Title:</td><td><input type="text" name="tytul" maxlength="100" size="50" value="<?php if($read && ($_GET['mode']=='edit')) echo $t; ?>"></td>

              </tr>

              <tr>

                  <td>Date:</td><td><input type="text" name="data" maxlength="20" size="20" value="<?php if($read && ($_GET['mode']=='edit')) echo str_replace(' ', ', ', $d); else print date("Y-m-d, H:i:s", time()); ?>"> (yyyy-mm-dd, hh:mm:ss)</td>

              </tr>

              <tr>

                  <script language="JavaScript" src="../config/func.js"></script>

                  <td></td>

                  <td>

                    <input type="button" accesskey="b" name="addbbcode0" value=" B " style="font-weight:bold; width: 30px; margin-top: 20px" onClick="bbstyle(0)">

                    <input type="button" accesskey="i" name="addbbcode2" value=" i " style="font-style:italic; width: 30px" onClick="bbstyle(2)">

                    <input type="button" accesskey="u" name="addbbcode4" value=" u " style="text-decoration: underline; width: 30px" onClick="bbstyle(4)">

                  </td>

              </tr>

              <tr>

                  <td valign="top">Text:</td><td><textarea name="text" cols="75" rows="18"><?php if($read && ($_GET['mode']=='edit')) echo $text; ?></textarea></td>

              </tr>

              <tr>

                  <td></td><td><input <?php echo (($read && ($_GET['mode']=='edit')) ? 'type="button"' : 'type="reset"'); ?> value="RESET" onClick="clear_form(this.form);">  

                          <input type="submit" value="<?php echo (($read && ($_GET['mode']=='edit')) ? 'EDIT NEWS' : 'ADD NEWS'); ?>"></td>

              </tr>

            </form>

        </table>

      <?php

        }

      elseif($form=='edit/delete')

        {

      ?>

        <table style="margin:10px">

            <tr bgcolor="#CCCCCC" style="font-weight:bold">

              <td width="20" align="center">ID</td>

              <td width="130">Date</td>

              <td width="250">Title</td>

              <td width="50"></td>

            </tr>

        <?php

            if ($result=mysql_query('SELECT `id_news`, `tytul`, `data` FROM `news` ORDER BY `data`'))

              {

              if (mysql_num_rows($result) > 0)

                  {

                  while($row=mysql_fetch_assoc($result))

                    {

                    echo '<tr onMouseOver="style.background=\'#eeeeee\'" onMouseOut="style.background=\'#ffffff\'" style="cursor: default">

                          <td style="color: #666666; text-align:center">' . $row['id_news'] . '</td>

                          <td>' . str_replace(' ', ', ', $row['data']) . '</td>

                          <td>' . $row['tytul'] . '</td>

                          <td style="color:#666666; font-size:10px; text-align: center"><a href="news.php?form=add&mode=edit&id=' . $row['id_news'] . '">edit[/url] | <a href="javascript:check(' . $row['id_news'] . ');">del[/url]</td>

                        </tr>';

                    }

                  }

              else

                  error('<tr><td colspan="3">No news in database table</td></tr>');

              }

            else

              error('<tr><td colspan="3">Error in SQL query! MySQL: ' . mysql_error() . '</td></tr>');

             

            mysql_free_result($result);

        ?>

        </table>

      <?php

        }

      }

  }

?>

</body>

</html>

#
#-----[ FIND ]------------------------------------------
#

else print date("Y-m-d, H:i:s", time()); ?>

#
#-----[ IN-LINE, FIND ]------------------------------------------
#

date("Y-m-d, H:i:s", time())

#
#-----[ REPLACE WITH ]------------------------------------------
#

date("Y-m-d")

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM

 

Should solve your problem.

 

Please post all code inside [ code] and [/ code] (without spaces) tags, it helps people find what we are looking for inside the code.

Sorry it took so long to reply, after doing the previous one, try this:

 

#
#-----[ FIND ]------------------------------------------
#

else print date("Y-m-d, H:i:s", time()); ?> (yyyy-mm-dd, hh:mm:ss)

#
#-----[ IN-LINE, FIND ]------------------------------------------
#

(yyyy-mm-dd, hh:mm:ss)

#
#-----[ REPLACE WITH ]------------------------------------------
#

(yyyy-mm-dd)

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM

 

I don't know if that will work, I'd need to see the page you are working on before I an really know what to do, also, try using single quotes for the date instead of double quotes, that might work.

 

Hope this helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.