- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
MySQL 数据库由以下列名组成:id、store、results,有 350 行。
我有一个名为“随机播放”的按钮。当我单击该按钮时,我会从 MySQL 数据库(selectshuffle.php)打印 3 个随机行。每行结果都有一个“选择”按钮(getdata.php)
当我单击一行上的“选择”按钮时,列名“记录”应更新为 +1。
我可以在我发布的代码中使用 +1 更新该行,并收到消息“Updated Succesfull”,但前提是我使用如下数字设置值:
<input type="hidden" value="333" name="id" />
但我需要更新列名“结果”,在该 ID 上我单击“选择”。我想我可以这样做:<input type="hidden" value="<?php $_POST['id']; ?>" name="id" />
。使用此代码,我仍然收到消息“Updated Succesfull”,但没有行受到影响。
有人能看出我做错了什么吗?
index.php
<form action="updaterecords.php" method="post">
<input type="hidden" value="333" name="id" />
<button type="submit" name="selectStore" >Select</button>
<button type="button" data-dismiss="modal">Close</button>
</form>
updaterecords.php
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
if (mysqli_connect_errno()) { echo "Error: no connexion allowed : " . mysqli_connect_error($mysqli); }
?>
<?php
include 'dbconnection.php';
if(isset($_POST['selectStore'])) {
$id = $_POST['id'];
$stmt = $mysqli->prepare("UPDATE stores SET records = records + 1 WHERE id = ?");
$stmt->bind_param('i', $id);
$stmt->execute();
$stmt->close();
$mysqli->close();
if($stmt) {
echo "Updated Succesfull";
} else {
echo "Failed: " . $stmt->error;
}
}
?>
getdata.php
<?php
include 'dbconnection.php';
if(isset($_POST['post_id'])) {
$id = $_POST['post_id'];
$sql = "SELECT id, store, results FROM stores WHERE id = ".$id;
$res = $mysqli->query($sql);
if($res){
$data = $res->fetch_assoc();
echo json_encode($data);
}else{
echo "no results: <br>";
echo $sql;
}
}
?>
selectshuffle.php
<?php
include 'dbconnection.php';
$sql = "SELECT id, store, results FROM stores WHERE 1=1 ORDER BY RAND ( ) LIMIT 3";
$res = $mysqli->query($sql);
if ($res->num_rows > 0) {
while($row = $res->fetch_assoc()) {
echo "Id: " . $row["id"]. "<br>" .
"Store: " . $row["store"]. "<br>" .
"Result: " . $row["results"]. "<br><br>".
'<div class="btn btn-warning btn-open-modal" data-id="'.$row["id"].'">See Details '.'</div><br><br>';
}
} else {
echo "There is no results";
}
?>
<div class="modal fade" id="editBox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><center>Get Heading</center></h4>
</div>
<div class="modal-body">
<div class="form-data"></div>
<p>Get Description</p>
</div>
<div class="modal-footer msg">
<form action="updaterecords.php" method="post">
<input type="hidden" value="333" name="id" />
<button type="submit" name="selectStore" >Select</button>
<button type="button" data-dismiss="modal">Close</button>
</form>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$(".btn-open-modal").click(function() {
var id = $(this).data("id");
$.ajax({
type: 'post',
url: 'getdata.php',
data: {
post_id: id
},
success: function(data) {
console.log(data);
var jdata = JSON.parse(data);
if (jdata) {
console.log("is json");
$("#editBox").modal().show();
$("#editBox .modal-title").html(jdata.headline);
$("#editBox .modal-body").html("Store: " + jdata.store + "<br><br>Result: " + jdata.results); // + " " + $query $query => query
} else {
console.log("not valid json: " + data);
}
}
});
});
});
</script>
最佳答案
给你的id input
一个id,这将用于设置从getdata.php
返回的id
<form action="page.php" method="post">
<input type="hidden" id="store-id" value="" name="id" />
<button type="submit" name="selectStore" >Select</button>
<button type="button" data-dismiss="modal">Close</button>
</form>
然后在 ajax 调用中设置输入的值。
$(".btn-open-modal").click(function() {
var id = $(this).data("id");
$.ajax({
type: 'post',
url: 'getdata.php',
data: {
post_id: id
},
success: function(data) {
console.log(data);
var jdata = JSON.parse(data);
if (jdata) {
$("#editBox").modal().show();
$('#store-id').val(jdata.id); // set the value from the returned data
$("#editBox .modal-title").html(jdata.headline);
$("#editBox .modal-body").html("Store: " + jdata.store + "<br><br>Result: " + jdata.results); // + " " + $query $query => query
} else {
console.log("not valid json: " + data);
}
}
});
});
关于php - html 值和准备好的语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43824155/
我想获取当前位置并将相机移动到当前位置,然后将当前位置 (LatLng) 保存到我的数据库 我获得了 ACCESS_FINE 权限并使用以下代码,但应用程序已停止工作 double lat = map
我想稍微优化一下这部分代码,以使用 $_SESSION['user']= $arr; 这样的数组。 // Store user db info in session for use $stmt = $
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我不确定 DaemonSet 中是否存在就绪条件。我的意思是,该 DaemonSet 拥有的所有 pod 都已准备就绪。 我知道 kubectl wait ,不过好像不能检查 DaemonSet 的准
我正在编写一个 JS 模块模式来测试代码并帮助我使用 JS Fiddle 理解该模式。我不明白的是,为什么第 25 行和第 26 行的“私有(private)方法”在通过 DOM 就绪引用时,其值为未
标题中有一个非常微妙的动画。当第一次加载页面,或者使用 cmd+shift+r (mac) 刷新以清除缓存时,jQuery 似乎并没有等待 DOM 准备好。它在所有正常的 html/css 弹出之前启
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我有两个问题: 我如何知道框架的内容已准备就绪/已加载(如 $(document.ready()))? 我如何知道弹出窗口 (window.open()) 内容已准备就绪/已加载(如 $(docume
只是想知道 document.ready 调用的数量是否会影响页面加载速度。Gulp/Grunt 有没有办法通过删除单独的文档就绪函数来丑化/缩小 JS? 最佳答案 检查一下! 我没有发现 Chrom
我有一个 的列表如下所示,它使用 Meteor.startup 填充了 find()。然后我得到这些 的所有数据属性使用 data() 并将其放入一个对象中并尝试返回/console.log 它以
我正在使用 trego 主题。作为主题选项,您可以设置和更改将出现在站点中的文本(例如“版权文本”和“ Logo url”的文本)。我如何使用 WPML 制作多语言版本?我想通过 wpml-confi
Zend_Service_Twitter 组件仍然适用于将于 2013 年 3 月 5 日弃用的 Twitters API v1.0。所以我想准备好我的新网站与 Twitter API 交互 v1.1
有没有一种优雅的方法来做到这一点?目前我只是使用自定义步骤 “并等待 10 秒”以绝对确定,有足够的时间让 iframe 做好准备。我不希望这个功能因为一个小的网络问题或 CPU 峰值而在我动力不足的
当我尝试在我的 VPS 上安装 Windows 时,我无法访问 Glish---图形网站控制台(但浏览器控制台可以工作)。 当我打开 Glish 控制台时,提示: novnc ready: nativ
生成新的全屏窗口时,相对于: sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) window = sdl2.ext.Window('win_name', (x_size, y_si
我刚刚为我的最新项目投入了 Umbraco ASP.NET CMS,我不确定这是否是全面的,但对于我的设置,Knockout.js 正在做所有的模板。 我不太热衷于 knockout.js,但到目前为
我是 jQuery 的新手,最近几天一直在尝试学习它。在我的办公室里,几乎没有经验丰富的 JavaScript 开发人员,他们主要使用 jQuery 来满足他们的所有需求,每当我找到他们并与他们交谈以
我目前正在编写一个脚本,我正在使用 while($IE.busy) {Start-Sleep 1} 等待页面准备就绪。 页面准备好后,我的脚本会填写并提交表单。我一直遇到问题,因为(我认为)IE 报告
这个问题已经有答案了: window.onload vs $(document).ready() (17 个回答) 已关闭 3 年前。 以下示例代码的执行顺序是什么?会$(window).on('lo
我是一名优秀的程序员,十分优秀!