我試圖推倒一些變量並將它們插入MySql數據庫,但由於某種原因,它不工作。我一直在努力幾個小時,而我只是不確定自己做錯了什麼。 如果你能幫助它,將不勝感激。implode()MySql查詢不能正常工作
$AddressString = "address1,address2,address3,address5,postcode";
$AddressSplit = explode(",", $AddressString); //split the address string
$StringLength = count($AddressSplit) - 1;
$s = 0; //trim any white spaces from the address string
while ($s < count($AddressSplit)) {
$AddressSplit[$s] = trim($AddressSplit[$s]);
$s++;
}
//Create the Values to insert into DB
$MysqlValues = implode("','", $AddressSplit);
$MysqlValues = "'$MysqlValues'";
$NumberVals = count($AddressSplit);
$t = 1;
while ($t < $NumberVals) {
$ad[$i] = "add$i";
$t++;
}
$TableNames = implode(", ", $ad);
mysql_query("INSERT INTO pstc_add_main (" . $TableNames . ",add10,date)
VALUES (" . $MysqlValues . ",'$cdate')");
}
代碼'echo'完整的查詢剛在調用'mysql_query'之前。 – Jocelyn
$ MysqlValues = implode(「','」,$ AddressSplit);應該是,$ MysqlValues = implode(「,」,$ AddressSplit); – FirmView
您的輸入字符串是否正確轉義/過濾?否則,你只是在尋找問題。 – knittl