我有每个产品的这些hiiden字段。我可以用jquery获得隐藏的字段。但是,当我输入数据时,它不会进入数据库,而是始终显示为0。我之所以这样,是因为它们具有相同的命名值。如何在不更改输入名称的情况下解决此问题!
我的数据库中也有一张表可以列出所有产品。
<select id="mySelect" onchange="npup.doSelect(this);" name="catagory" type="text">
<option value="">choice</option>
<option value="curtain_fabrics">Curtain Fabrics</option>
<option value="curtain">Curtains</option>
<option value="curtain_holder">Curtain Holders</option>
</select>
<div id="mySpecialElements">
<div id="npupcurtain_fabrics" class="hidden">
<div class="fe" >Quality: <input type="text" name="quality"> </div>
<div class="fe" >Width:<input type="text" name="width"> </div>
<div class="fe" >Price:<input type="text" name="price"> $/m</div>
</div>
<div id="npupcurtain" class="hidden">
<div class="fe" >Quality<input type="text" name="quality"></div>
<div class="fe" >Width:<input type="text" name="width"> </div>
<div class="fe" >Height:<input type="text" name="height"></div>
<div class="fe" >Price:<input type="text" name="price" >$/set</div>
</div>
<div id="npupcurtain_holder" class="hidden">
<div class="fe" >Material<input type="text" name="material"></div>
<div class="fe" >Moldel:<input type="text" name="model"> </div>
<div class="fe" >Price:<input type="text" name="price" >$/piece</div>
</div>
这是mysql代码:
$sql = mysql_query("INSERT INTO products (name, catagory, quality, width, height, price, date_add)
VALUES('$product_name','$product_category','$prosuct_quality','$produt_width','$product_height','$product_price', now())");
最佳答案
您可以将它们作为数组发送到服务器:
<div id="npupcurtain_fabrics" class="hidden">
<div class="fe" >Quality: <input type="text" name="fabrics[quality]"> </div>
<div class="fe" >Width:<input type="text" name="fabrics[width]"> </div>
<div class="fe" >Price:<input type="text" name="fabrics[price]"> $/m</div>
</div>
<div id="npupcurtain" class="hidden">
<div class="fe" >Quality<input type="text" name="npupcurtain[quality]"></div>
<div class="fe" >Width:<input type="text" name="npupcurtain[width]"> </div>
<div class="fe" >Height:<input type="text" name="npupcurtain[height]"></div>
<div class="fe" >Price:<input type="text" name="npupcurtain[price]" >$/set</div>
</div>
<div id="npupcurtain_holder" class="hidden">
<div class="fe" >Material<input type="text" name="holder[material]"></div>
<div class="fe" >Moldel:<input type="text" name="holder[model]"> </div>
<div class="fe" >Price:<input type="text" name="holder[price]" >$/piece</div>
</div>
在服务器端..say
PHP
中,变量类似于:$_POST['fabrics']['quality'];
$_POST['holder']['model'];
....
关于php - 从隐藏的投入中获取值(value),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22589490/