【发布时间】:2020-05-16 19:20:29
【问题描述】:
我的 cookie 是这样的;
Array
(
[1] => 1
[12] => 1
)
我的表单输入像; (adet = 数量,idler = 英文ID)
<?php $postvalue = $_COOKIE['sepet'];
foreach($postvalue as $id =>$adet)
{
echo '<input type="hidden" name="idler[]" value="'. $id. '">';
echo '<input type="hidden" name="adet[]" value="'. $adet. '">';
} ?>
还有我的php文件;
if(isset($_POST['submit'])){
$adet = $_POST['adet'];
$idler = $_POST['idler'];
$sql = "UPDATE student SET urun_stok=:stok WHERE urun_id=:idler";
$query = $db->prepare($sql);
foreach( $idler as $key => $n ){
$query->bindparam(':idler', $idler[$key]);
$query->bindparam(':adet', $adet[$key]);
$query->execute();
}
}
模态js;
Modal Confirm
*/
$(document).on('click', '.modal-confirm', function (e) {
e.preventDefault();
$.magnificPopup.close();
$.ajax({
type: "POST",
url: "ge.php",
cache:false,
data: $('#modalAnim').serialize(),
});
new PNotify({
title: 'Success!',
text: 'Satış Başarılı.',
type: 'success'
});
});
我对 php 有点陌生,所以我试图通过 urun_stok 行上的 id 更新我的数据库行。 所以我猜我做错了:)
【问题讨论】:
-
Adet 和 stok 是不同的词
-
我已经添加了模态js,可能问题与js有关。
标签: php mysql arrays ajax foreach