我無法讓我的addslashes函數和html選項值在一起玩。我最初的問題是選項中的單引號,但通過解決,我似乎已經創建了另一個問題,即$ titleunit_name只能通過第一個單詞出現。php表單中的單引號和addslashes(選項值在空間上轉義?)
這是我想出來的:
baroffice =奧法倫&公路ķ&ň
titleunit_name =奧法倫&公路ķ&ň
cleantitleunit_name = O \」 Fallon & Highway K & N
這就是我得到的:
baroffice =奧法倫
titleunit_name =奧法倫&公路ķ&ň
cleantitleunit_name = O \'法倫&公路ķ&ň
我不知道,如果它的事項但值通常來自並被髮回到MS SQL。
<form method="post" action="formtest.php?" id="searchform" target="" autocomplete="off">
<div id="office">
<font style="font-size:12px; font-weight:bold;" color="#002EB8" face="Verdana">
Closing Office:</font>
<select name="baroffice" style="width:90px">
<?php
$titleunit_name= "O'Fallon & Highway K&N";
$cleantitleunit_name=addslashes("$titleunit_name");
echo "<option value=$cleantitleunit_name name= '$titleunit_name'>";
echo "$titleunit_name</option>";
?>
</select></div><br>
<br><Br>
<input type="submit" name="submit" value="submit" style="position:relative;z-index:3">
<br><Br>
</form>
<?php
$baroffice = str_replace("\'","'",($_POST['baroffice']));
if (isset($_POST['submit']))
{
echo "baroffice=$baroffice<br>";
echo "titleunit_name=$titleunit_name<br>";
echo "cleantitleunit_name=$cleantitleunit_name<br>";
}
else
{echo "";
};
?>
感謝您的任何幫助提前。
感謝您的幫助。它實際上不是mysql,而是ms sql的odbc。你還糾正了很多我的格式,並且做到了! – bnw 2010-10-12 21:19:55