php - Date column doesn't show right datestamp upon form submit to DB -
for reason or date , time in date column shows 0000-00-00 00:00:00
when submit form db. way can date right updating manually. started doing , i'm not sure changed. i'm having real hard time troubleshooting this.
edit form:
<?php if(!defined('in_admin')) exit; ?> <div class="page"> <h1 class="edit"><?=ucfirst($mode)?> post</h1> <span class="error-text"><?=$response_text?></span> <form action="admin.php?mode=<?=$mode?>&id=<?=$post['post_id']?>" method="post"> <p> <label for="title">post title:</label><br /> <input type="text" size="80" id="title" name="data[post_title]" value="<?=htmlspecialchars(stripslashes($post['post_title']))?>" /> </p> <p> <label for="title">upload image:</label><br /> <input type="text" size="80" id="title" name="data[image]" value="<?=htmlspecialchars(stripslashes($post['image']))?>" /> </p> <p> <label for="title">image alt:</label><br /> <input type="text" size="80" id="title" name="data[image_alt]" value="<?=htmlspecialchars(stripslashes($post['image_alt']))?>" /> </p> <p> <label for="title">post category:</label><br /> <input type="text" size="80" id="title" name="data[post_category]" value="<?=htmlspecialchars(stripslashes($post['post_category']))?>" /> </p> <p> <label for="content">post insert:</label><br /> <textarea cols="77" rows="10" id="insert" name="data[post_insert]"><?=htmlspecialchars(stripslashes($post['post_insert']))?></textarea><br /> <span class="form-text">brief little tid-bit article home page</span> </p> <p> <label for="content">post content:</label><br /> <script>edtoolbar('mytxtarea'); </script> <textarea cols="77" rows="10" id="mytxtarea" class="ed" name="data[post_content]"><?=htmlspecialchars(stripslashes($post['post_content']))?></textarea><br /> <span class="form-text">to format use raw html.. <strong>, <span>, etc</span> </p> <p> <label for="status">post status:</label><br /> <select id="status" name="data[published]"> <?=generate_option_list(array('0' => 'unpublished', '1' => 'published'), $post['published'])?> </select> </p> <p> <input class="button" type="submit" name="miniblog_postback" value="<?=ucfirst($mode)?>" /> </p> </div>
that's form use, , here index.php form in:
case 'add': if(isset($_post['miniblog_postback'])) { $data = $_post['data']; $data['post_slug'] = mb_slug($_post['data']['post_title']); $data['date'] = time(); $sql =''; $i = 1; foreach($data $field => $value) { if($value == '') { $failed = true; break; } $fields .= "`" . mysql_real_escape_string($field) . "`"; $values .= "'" . mysql_real_escape_string($value) . "'"; $values .= ($i == sizeof($data)) ? '' : ', '; $fields .= ($i == sizeof($data)) ? '' : ', '; $i++; } $post = $_post['data']; if($failed) { $response_text = 'error: must fill out fields'; } else { $result = mysql_query("insert `db` ({$fields}) values({$values})"); $response_text = ($result) ? 'post added' : 'post not added'; } } include('edit.php'); break;
$data['date'] = time();
should be:
$data['date'] = date("y-m-d h:i:s");
the time()
function returns current time in number of seconds since unix epoch (january 1 1970 00:00:00 gmt).
the date()
function formats local date , time (by default current one), , returns formatted date string, in case, in format mysql needs it.
Comments
Post a Comment