0
此代碼正常工作:$ batsman1name作爲新值插入數據庫的正確行中。MySQL查詢中的PHP變量
for($count = 1; $count <= 22; ++$count)
{
$setbattingid = 'batsman' . $count . 'battingid';
$$setbattingid = mysql_real_escape_string($_POST[$setbattingid]);
$setname = "batsman" . $count . "name";
$$setname = mysql_real_escape_string($_POST[$setname]);
$query = "UPDATE batting_new SET batsmanname = NULLIF('$batsman1name', '') WHERE battingid = '$batsman1battingid'";
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
}
有了這個代碼數據庫沒有更新,但varaible變量$$的setName和$$ setbattingid確實包含爲$ batsman1name以上$ batsman1battingid相同的值。
for($count = 1; $count <= 22; ++$count)
{
$setbattingid = 'batsman' . $count . 'battingid';
$$setbattingid = mysql_real_escape_string($_POST[$setbattingid]);
$setname = "batsman" . $count . "name";
$$setname = mysql_real_escape_string($_POST[$setname]);
$query = "UPDATE batting_new SET batsmanname = NULLIF('$$setname', '') WHERE battingid = '$$setbattingid'";
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
}
任何想法?如果我沒有很好地解釋我的問題,讓我知道嗎?謝謝。
謝謝! – 24ma13wg