如何在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个回答



您没有在edit.php页面中使用表单操作。 </ p>
</ div>

展开原文

原文

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

dongpangfu6322
dongpangfu6322 <form action =“_ processSaveNews.php”class =“form-horizo​​ntal form-b​​ordered”method =“post”name =“frmAddNews”enctype =“multipart / form-data”>
12 个月之前 回复
douzhi2012
douzhi2012 您没有提到表单操作到哪个页面提交您的日期?
12 个月之前 回复
dongqin1861
dongqin1861 <div class =“form-group col-md-12 center”> <button type =“submit”class =“btn btn-primary hidden-xs”>保存</ button> <button type =“submit”class =“ btn btn-primary btn-block btn-lg visible-xs mt-lg“>保存</ button> </ div>
12 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问