2017-02-14 37 views
0

我正在與以下行錯誤:問題用PHP串聯

$get = mysql_fetch_assoc($result);  
$id = $_REQUEST['id']; 
echo '<form action="invoices.php?id=$id" method="POST">'; 
echo '<label>Invoice ID: </label>'. $id. '<br>'; 
echo '<label>User ID: </label>'. $get['customer_id']. '<br>'; 
echo '<label>Set Status: </label> <select name="status" id="status"> 
<option value="Unpaid"'.**if($get[/'status/'] == "Unpaid"**){ echo " selected";}.'>Unpaid</option> 
<option value="Paid"'.**if($get[/'status/'] == "Paid"**){ echo " selected";}.'>Paid</option> 
<option value="Cancelled"' **.if($get[/'status/'] == "Cancelled"**){ echo " selected";}.'>Cancelled</option> 
</select>'; 

錯誤就說明是意外如果線XX聲明

問題是用PHP連接兩個字符串..誰能幫我糾正if語句?

+0

這些是什麼星號?你的代碼似乎很錯誤。嘗試使用類似於:'echo'';' –

回答

0

我喜歡這種格式:

echo '<form action="invoices.php?id=' . $id . '" method="POST">'; 
echo '<label>Invoice ID: </label>'. $id. '<br>'; 
echo '<label>User ID: </label>'. $get['customer_id']. '<br>'; 
echo '<label>Set Status: </label> 
    <select name="status" id="status"> 
     <option value="Unpaid"' . ($get['status'] == 'Unpaid' ? ' selected' : '') . '>Unpaid</option> 
     <option value="Paid"' . ($get['status'] == 'Paid' ? ' selected' : '') . '>Paid</option> 
     <option value="Cancelled"' . ($get['status'] == 'Cancelled' ? ' selected' : '') . '>Cancelled</option> 
    </select>'; 
+0

但是你沒有使用If語句?它將如何顯示選定的保存價值? – Sohail

+0

哦,我明白了。讓我試試這個! – Sohail

0

這個怎麼樣?

$get = mysql_fetch_assoc($result);  
$id = $_REQUEST['id']; 
echo '<form action="invoices.php?id=' . $id . '" method="POST">'; 
echo '<label>Invoice ID: </label>'. $id. '<br>'; 
echo '<label>User ID: </label>'. $get['customer_id']. '<br>'; 
echo '<label>Set Status: </label> <select name="status" id="status"> 
<option value="Unpaid"'; if($get['status'] == "Unpaid"){ echo "selected"; } echo '>Unpaid</option> 
<option value="Paid"'; if($get['status'] == "Paid"){ echo "selected"; } echo '>Paid</option> 
<option value="Cancelled"'; if($get['status'] == "Cancelled"){ echo " selected";} echo '>Cancelled</option> 
</select>'; 

實際上並沒有加入字符串,但這會幫助你。

+1

表單操作中的$ id不會被替換,因爲使用了單引號。 – Cashbee

+0

正確,修復它。 – Areeb