我试图从jQuery中获得价值,认为它是将其他值存储到数据库中的条件。
这里是我的jQuery代码:POST方法不起作用
$('#button').click(function() {
var s;
$.each($('#main li.' + set.select + ' a'), function (index, value) {
s = $(this).attr('name');
alert(s);
$.post('random.php',
{
id:s
})
});
})
,我借此s
到PHP:
$con=mysqli_connect(" ") ;
$id=$_POST['s'] ;
if(substr($id,0,1)=='1'){
$a = '24 june';
}
else if(substr($id,0,1)=='2'){
$a = '25 june';
}
else if(substr($id,0,1)=='3'){
$a = '26 june';
}
else if(substr($id,0,1)=='4'){
$a = '27 june';
}
else if(substr($id,0,1)=='5'){
$a = '26 june';
}
mysqli_query($con,"UPDATE `comp1` SET `col1` ='Booked!' where Day = '$a' ");
我的表中有一个名为“日”列,该列包含日期以上 我无法更新数据在行中,无论s
是什么值,name
都是一个数字。我也尝试使用toString
作为name
,但它没有奏效。
正确。而's'只是JavaScript中的一个赋值变量。 – JakeGould
好的,谢谢,我得到了第一个,但我不完全得到attr('name'),我认为它现在是一个字符串,因此它可以通过 – user3761386
@ user3761386阅读编辑 – vico