php - PHP代码不允许多个输入值通过我的表单发送

原文 标签 php html

PHP code isn't allowing multiple input values to send through my form

I am running into a wall with an application I have built. I am brand new to PHP (less than 1 month) and I have written a very complex form with the help of a mentor. Due to a confidentiality agreement I cannot send my entire code here for an example. Specifically the issue I am having is that my form isn't able to send multiple values to two different input "slots". It will send a singular input value to the database, but it should be registering the different values inputted.

<?php                        
{
foreach($results['tags'] as $part){
if ($part['category'] == "Part"){
?>
<tr>
<td><?= $part['Part']; ?></td>
<td class="text-center"><?= $product['Amount']; ?></td>
<td><input type="text" name=$product['Val1'] /></td>
<td><input type="text" name=$product['Val2'] /></td>
</tr>

<?php
    }
      }

         }

            ?>

My mentor suggested this as an answer but I am not sure what he means: "It seems like the [val1/2] needs to be tied to the product instead of the transaction. Right now, it’s not inside that “tags” section. Does that make sense?"

Answer

You're trying to name your vars with $. I suppose you want to output php values there, so change your string to look like this:

<td><input type="text" name="<?= $product['Val1'] ?>"/></td>

翻译

我正在使用自己构建的应用程序碰壁。我是PHP的新手(不到1个月),并且在导师的帮助下写了一个非常复杂的表格。由于保密协议,我无法在此处发送我的完整代码作为示例。具体来说,我遇到的问题是我的表单无法将多个值发送到两个不同的输入“插槽”。它将向数据库发送一个单一的输入值,但是它应该注册输入的不同值。

<?php                        
{
foreach($results['tags'] as $part){
if ($part['category'] == "Part"){
?>
<tr>
<td><?= $part['Part']; ?></td>
<td class="text-center"><?= $product['Amount']; ?></td>
<td><input type="text" name=$product['Val1'] /></td>
<td><input type="text" name=$product['Val2'] /></td>
</tr>

<?php
    }
      }

         }

            ?>


我的导师建议将此作为答案,但我不确定他的意思是:
“ [val1 / 2]似乎需要绑定到产品而不是交易上。现在,它不在“标签”部分内。这有意义吗?”
最佳答案
您正在尝试使用$命名您的var。我想您想在那里输出php值,因此将字符串更改为如下所示:

<td><input type="text" name="<?= $product['Val1'] ?>"/></td>
相关推荐

php - Laravel 5.1内部联接查询中的问题

php - 控制PHP ldap分页-结果数和页码

php - 带有PHPStorm 10的PHP7

php - 如何防止第二个正则表达式重新替换?

php - 如何在PHP的$ _SESSION中保存值并进行检索

php - 与特质的定义顺序和内容有关的“未找到特质错误”

php - 按费用和名称对数组进行排序

php - WAMP上的Mysqli,错误-连接尝试失败

php - laravel查询返回奇怪的顺序

php - Silverstripe 3.2-如何在不同选项卡的ModelAdmin中管理同一数据对象的不同列表