2013-10-14 63 views
0

奇怪的情況,我不明白爲什麼我的PHP腳本不通過HTML代碼。無法傳遞HTML數據通過PHP

好吧,我正在我的網站上工作,並根據免費和高級配置文件類型來顯示WYISIWYG文本編輯器。我使用簡單的「a」,「b」和「c」來表示我的mysql數據庫中的免費和溢價。

但是,當我試圖製作腳本並運行時,它僅顯示「b」和「c」帳戶類型的數據,但沒有顯示「a」類型的數據。

這是我的代碼。

<?php 
include_once("../scripts/userlog.php"); (it is where i assign id to users) 
$id = "$log_id"; 

$sql_type = mysql_query("SELECT acc_type FROM members WHERE id='$id' LIMIT 1"); 
while($row = mysql_fetch_array($sql_type)){ 

$acc = $row["acc_type"]; 

if($acc = "a"){ 

$field = '<div id="wysiwyg_cp" style="padding:8px; width:700px;"> 
<input type="button" onClick="iBold()" value="B"> 
<input type="button" onClick="iUnderline()" value="U"> 
<input type="button" onClick="iItalic()" value="I"> 
<input type="button" onClick="iFontSize()" value="Text Size"> 
<input type="button" onClick="iForeColor()" value="Text Color"> 
<input type="button" onClick="iHorizontalRule()" value="HR"> 
<input type="button" onClick="iUnorderedList()" value="UL"> 
<input type="button" onClick="iOrderedList()" value="OL"> 
<input type="button" onClick="iLink()" value="Link"> 
<input type="button" onClick="iUnLink()" value="UnLink"> 
<input type="button" onClick="iImage()" value="Image"> 
</div> 
<!-- Hide(but keep)your normal textarea and place in the iFrame replacement for it --> 
<textarea style="display:none;" name="content" id="content" cols="100" rows="14">                         </textarea> 
<iframe name="richTextField" id="richTextField" style="border:#000000 1px solid;  width:700px; height:300px;"></iframe> 
<!-- End replacing your normal textarea -->'; 
} 

if($acc = "b"){ 

$field = 'adding soon'; 
} 

if($acc = "c"){ 
    $field = 'adding soon'; 
} 
} 
?> 

當我運行該腳本,我只得到 「立即補充」

+0

怎麼能你代表三種不同設置的賬戶類型? – ceejayoz

+3

** == **是比較** = **是分配 – 2013-10-14 19:54:57

回答

4

在您的比較是這樣的:

if($acc = "a"){ 

您應該使用=====供對比,不是=。您正在按照自己的方式將值分配給變量。

+0

您還應該注意,作業總是評估爲'true' iirc。 – nietonfir

+0

@nietonfir作業將評估分配的值。因此,如果您爲變量分配了錯誤的值,則評估將是錯誤的。它給變量賦了一個真值,它會評估爲真。 –

+0

你當然是對的。 「* [*]他的**作業[*] *。;-)錯過了*他的* – nietonfir

0

您的所有條件都不正確。條件運算符是'=='而不是'='。所以,在所有的條件語句把 '==',而不是 '='

0

if語句是不正確的......

if ($a = 1) 
    } 
    // do something 
    } 

這將設置$ a的值1

if ($a == 1) 
    { 
    // do something 
    } 

這將比較$ a到1

0

您使用的是IFS是不正確的方式,應該是沒有= = =,例如

if ($acc == "a") 
{ 
    //do something 
} 
else 
{ 
    //do other thing 
} 

我建議你把它寫這樣

if ("a" == $acc) 
    { 
     //do something 
    } 
    else 
    { 
     //do other thing 
    } 

爲什麼要使用它這樣的嗎?那麼,因爲這樣,如果你錯過了a =將不能夠修改變量「a」,因爲它的一個字符和編譯器會給你錯誤,而不是覆蓋變量的值$ acc