更新数据库与javascript AJAX功能通过按钮
update database with javascript AJAX function through button
我想我的数据库表更新时,按钮租用点击我找不到问题。我没有收到任何错误,但我的表不会更新,我希望有人能请在我的脚本下面,并能够指出我的错误。
这是我的hire_staff.php文件
<?php
session_start();
include("header.php");
?>
<?php
$chief_aerodynamicist = $staff['chief_aerodynamicist'];
$chief_designer = $staff['chief_designer'];
$commercial_director = $staff['commercial_director'];
$pit_crew = $staff['pit_crew'];
$technical_director = $staff['technical_director'];
?>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".button").click(function(e){
$.ajax({
url: "hire.fire.php",
type: "POST",
data: {colID: e.target.id},
success: function(data){
data = JSON.parse(data);
}
});
});
});
</script>
</head>
<center><h2>You can hire new staff here</h2></center>
<table cellpadding="3" cellspacing="5">
<tr>
<td>Chief Aerodynamicist:</td>
<td><i><?php echo "Level $chief_aerodynamicist"; ?></i></td>
<td><form><input type="button" class="button" id="chief_aerodynamicist" value="Hire!"/></form></td>
</tr>
<tr>
<td>Chief Designer:</td>
<td><i><?php echo "Level $chief_designer"; ?></i></td>
<td><form><input type="button" class="button" id="chief_designer" value="Hire!"/></form></td>
</tr>
<tr>
<td>Commercial Director:</td>
<td><i><?php echo "Level $commercial_director"; ?></i></td>
<td><form><input type="button" class="button" id="commercial_director" value="Hire!"/></form></td>
</tr>
<tr>
<td>Pit Crew:</td>
<td><i><?php echo "Level $pit_crew"; ?></i></td>
<td><form><input type="button" class="button" id="pit_crew" value="Hire!"/></form></td>
</tr>
<tr>
<td>Technical Director:</td>
<td><i><?php echo "Level $technical_director"; ?></i></td>
<td><form><input type="button" class="button" id="technical_director" value="Hire!"/></form></td>
</tr>
</table>
<?php
echo "$colID";
include("footer.php");
?>
和my hire.fire.php
<?php
include("functions.php");
connect();
if(isset($_POST['colID'])){
$colID = mysql_real_escape($_POST['colID']);
$userID = mysql_real_escape($_SESSION['uid']);
mysql_query("UPDATE `staff` SET `$colID` = '6' WHERE `id`='$userID'") or die(mysql_error());
$query = mysql_query("SELECT FROM `staff` WHERE `id`='$userID'")or die(mysql_error());
$results = mysql_fetch_assoc($query);
echo json_encode($results);
}
?>
我不知道这是否有帮助,但一旦我有一个类似的查询相同的问题。我只是去掉了反引号(' '),它就工作了。我会尝试使用:
UPDATE staff SET $colID = '6' WHERE id = '$userID'
不是UPDATE `staff` SET `$colID` = '6' WHERE `id` = '$userID'
相关文章:
- 用于导出Excel的.Net MVC 4.5 JqGrid按钮功能不起作用.什么'我的代码错了
- 多按钮功能
- 如何将JsBarcode放入javascript按钮功能中
- 选项卡按钮功能
- j查询禁用按钮功能在第二次点击
- 交通信号灯点击按钮功能
- 按钮功能,如果按钮被按下 10 秒钟
- 更新引导拆分按钮文本并使用下拉按钮功能
- 动态更改点击事件上的按钮功能
- 阻止安卓后退按钮功能
- 使用提交按钮功能调试javascript中的问题
- RoR 3.1-用于锁定用户的按钮_功能
- 当我将鼠标悬停在通过按钮功能添加的表行上时,如何更改列中的图像
- Jquery UI按钮功能在弹出对话框打开时执行
- Javascript在一定条件下的点击按钮功能
- 在不加载页面的情况下保留后退按钮功能
- 按钮功能不重复
- 复制Next &上一页按钮功能
- 按钮与单选按钮功能
- Android (Tasker) -如何模拟返回按钮功能