我正在使用核心php制作数据库,数据库:-mysql。 我创建了管理面板来添加更新和删除我网站的某些部分。 因此,当我编辑数据库中未更改的日期时,一旦在数据库中保存了日期,我就会添加日期字段。 谁能帮我做到这一点。
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>
数据库查询:-
$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.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;
}
});
请尽快提供帮助。 预先感谢。
答案 0 :(得分:-1)
您没有在edit.php页面中使用表单操作。