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.

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?