我試圖從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