2014-11-05 91 views
-3

我有一個php數組元素想要提交作爲POST值,但它只接受由於間距的第一個單詞。下面是我的源代碼:如何將包含空格的php變量存儲到html變量中?

<input type="number" class="form-control" placeholder="Please enter the amount to order" size="5" name='.$row["fname"].' /> 

當頁面打印它顯示爲:

<input type="number" class="form-control" placeholder="Please enter the amount to order" size="5" name=Mussel in Chill Sauce /> 

正如你所看到的,只有兩個字「貽貝」被存儲到HTML表單的name變量。我如何儲存全文「辣椒醬中的貽貝」,它源於我的$row["fname"]

感謝您的幫助感謝

+2

內'NAME = 「 '$行[ 」FNAME「]。'」/ >''。或者用'printf()'代替。另外,順便說一下,'name'是一個*屬性*,不是HTML變量。 HTML沒有變量。 – 2014-11-05 12:55:39

+0

[HTML5佔位符屬性不能代替標籤元素](http://www.456bereastreet.com/archive/201204/the_html5_placeholder_attribute_is_not_a_substitute_for_the_label_element/) – Quentin 2014-11-05 12:56:34

+0

name是HTML標籤的屬性。 HTML中的所有屬性均應使用雙引號。 – newman 2014-11-05 12:59:26

回答

2

你應該將它們包裝在引號正確:

echo ' 
    <input 
     type="number" 
     class="form-control" 
     placeholder="Please enter the amount to order" 
     size="5" 
     name="'.$row["fname"].'" /> 
'; 

旁註:那不是一個好名字值,你確定這是你想要的值?你應該考慮把其他名稱值,而不是因爲這會看起來像$_POST變量中其提交時:

Array 
(
    [Mussel_in_Chill_Sauce] => 1 // going to access this thru $_POST['Mussel_in_Chill_Sauce'] ? 
) 
0

加引號的屬性值包含空格。

對於這個問題,圍繞所有屬性值加引號。他們有時是可選的,從不禁止。

0

我認爲這樣做會幫助你:)。

name="'.$row["fname"].'" 
0

更改代碼這個有name雙引號

<input type="number" class="form-control" placeholder="Please enter the amount to order" size="5" `name="'.$row[fname']." />`