我想使用ajax和php更新mysql数据库中的数据。
HTML
<td><input type="text" class="event" name="title<?php echo $row['id']?>" id="title_id_<?php echo $row['id']?>" value="<?php echo $row['title']?>" disabled/></td>
<td><input type="datetime" class="event" name="start<?php echo $row['id']?>" id="start_id_<?php echo $row['id']?>" value="<?php echo $row['start']?>" disabled/></td>
<td><input type="datetime" class="event" name="end<?php echo $row['id']?>" id="end_id_<?php echo $row['id']?>" value="<?php echo $row['end']?>" disabled/></td>
<td><div class="edit_wrapper"><a href="#" class="edit_button" id="edit-<?php echo $row['id'] ;?>"><img src="http://icons.iconarchive.com/icons/custom-icon-design/flatastic-1/24/edit-icon.png"/></a></td>
<td><div class="up_wrapper"><a href="" class="up_button" id="up-<?php echo $row['id'] ;?>"><img src="http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/24/Actions-svn-update-icon.png"/></a></td>
<td><div class="del_wrapper"><a href="" class="del_button" id="del-<?php echo $row['id'] ;?>"><img src="http://icons.iconarchive.com/icons/hopstarter/button/24/Button-Delete-icon.png"/></a></td>
jQuery Ajax代码
$('.up_button').click(function(){
var btnid=this.id;
btnid=btnid.replace(/\D/g, '');
btnid=parseInt(btnid, 10);
var e_title=$('#title_id_'+btnid).val();
var e_start=$('#start_id_'+btnid).val();
var e_end=$('#end_id_'+btnid).val();
$.ajax({
url: 'event_update.php',
data:{'title':e_title , 'id':btnid , 'start':e_start, 'end': e_end},
type: "POST",
success: function() {
alert("Güncelleme başarılı.");
}
});
});
这里是我的PHP代码(event_update.php)
<?php
include_once("config.php");
$id = $_POST['bid'];
$title = $_POST['title'];
$start = $_POST['start'];
$end = $_POST['end'];
mysql_query("UPDATE evenement SET title=$title,start=$start,end=$end WHERE id=$id"))
mysql_close($connecDB);
?>
但我无法更新数据。你可以帮忙吗?
答案 0 :(得分:1)
用此替换您的查询行,必须包含任何非数字实体。
mysql_query("UPDATE evenement SET title='$title',start='$start',end='$end' WHERE id='$id'"))