dou4064 2019-07-18 10:32 采纳率: 100%
浏览 100

如何在php中使用jquery更新当前日期

i am making website using core php ,database:-mysql. i have created admin panel to add update and delete some sections of my website. so i am adding date field once date is saved in database when i edit the date its doesn't change in database. can anybody please help me to do this.

HTML :-

<div class="form-group">
<label class="col-md-3 control-label" for="inputDefault"> Published Date * 
</label>
<div class="col-md-6">
<input type="date" class="form-control" id="publishedDate" 
name="publishedDate">
</div>
</div>

database query:-

$getreguser     = "INSERT INTO news (news_title, news_short_desc, news_long_desc, news_author, news_image, news_status , news_published_date ) VALUES ( :news_title, :news_short_desc, :news_long_desc, :news_author, :news_image, :status, :udate )";

        $setregusers    = $dbh->prepare($getreguser);

        $setregusers->bindParam(':news_title', $news_title);
        $setregusers->bindParam(':news_short_desc', $short_description);
        $setregusers->bindParam(':news_long_desc', $long_description);
        $setregusers->bindParam(':news_author', $news_author);
        $setregusers->bindParam(':news_image', $thumbname);         
        $setregusers->bindParam(':status', $status);
        $setregusers->bindParam(':udate', $udate);

        if ($setregusers->execute()) {
            echo $response = "success";
            exit;
        } else {
            print_r($dbh->errorInfo()); 
            echo $response = "failure";
            exit;
        }

edit.php:-

<?php 
$explodeNpd = explode(" " ,$udate);
$date = $explodeNpd[0];

?>  

<div class="col-md-6">
<input type="date" class="form-control"  id= "publishedDate" name="publishedDate" value= "<?php echo $date; ?>">

</div>
</div>
<div class="form-group col-md-12 center" >
<button type="submit" class="btn btn-primary hidden-xs">Save</button>
<button type="submit" class="btn btn-primary btn-block btn-lg visible-xs mt-lg">Save</button>
 </div>     

update query(update.php):-

$cId                     = $_POST['id'];
$news_title              = $_POST['title'];
$short_description       = $_POST['shortDescription'];
$long_description        = $_POST['longDescription'];
$news_author             = $_POST['newsAuthor'];
$cimage                  = $_POST['coldthumb'];
$status                  = $_POST['status'];
$udate                   = date('Y-m-d H:i:s');
// echo "<pre>";
// print_r($_POST);
//print_r($_FILES);

if ($_POST) {
try {

    if ($_FILES['file']['tmp_name'] != "") {

        $cimage         = $cat_name . "_" . date('Y-m-d-h-i-s') . "_" . $_FILES['file']['name'];
    } else {

        $cimage         = $cimage;
    }

    $getregcat             = "UPDATE  news SET news_title = :news_title, news_short_desc = :news_short_desc, news_long_desc = :news_long_desc, news_author = :news_author, news_image = :thumbname, news_status = :status, news_published_date = :udate WHERE news_id = :news_id";
    //  exit;

    $setregcat            = $dbh->prepare($getregcat);

    $setregcat->bindParam(':news_title', $news_title);
    $setregcat->bindParam(':news_short_desc', $short_description);
    $setregcat->bindParam(':news_long_desc', $long_description);
    $setregcat->bindParam(':news_author', $news_author);
    $setregcat->bindParam(':thumbname', $cimage);
    $setregcat->bindParam(':status', $status);
    $setregcat->bindParam(':udate', $udate);
    $setregcat->bindParam(':news_id', $cId);

jquery:-

submitHandler: function(form) {

  var file_data = $('#fileNewsImage').prop('files')[0];   
  var form_data = new FormData($('#frmEditNews')[0]); 

  form_data.append('file', file_data);
  form_data.append('title', $('#txtNewsName').val());
  form_data.append('shortDescription', $('#txtShortDescription').val());
  form_data.append('longDescription', $('#txtLongDescription').val());
  form_data.append('newsAuthor', $('#txtAuthorName').val());
  form_data.append('status', $('input[name=radStatus]:checked', '#frmEditNews').val());
  form_data.append('udate', $('#publishedDate').val());
  form_data.append('id', $('#hidNewsId').val());
  form_data.append('coldthumb', $('#hidNewsThumb').val());

  $.ajax({
      url: '_processEditNews.php', // point to server-side PHP script 
      dataType: 'text',  // what to expect back from the PHP script, if anything
      cache: false,
      contentType: false,
      processData: false,
      data: form_data,                       
      type: 'post',
      success: function(response){
        //alert(response); // display response from the PHP script, if any

        if(response == 'success'){

          alert('Record updated successfully!');
          window.location = 'news_management.php?response=success';

        }else if(response == 'failure'){
          $('#loginError').text('Error occured while saving data!');
        }
      }
   });

  return false;

}
 });

please help as soon as possible. thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongzhi4239 2019-07-18 10:43
    关注

    You Didn't used form action in your edit.php page.

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)