2014-11-05 96 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']." />`