Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTML和PHP一起形成_Php_Html - Fatal编程技术网

HTML和PHP一起形成

HTML和PHP一起形成,php,html,Php,Html,我想构建html表单,它将显示数据库中的数据。我想在表单的操作文件中修改这些 但是我的构造不起作用 这是我的代码: <?php //include 'readHersteller.php'; //$hersteller = $resultIDs; $hersteller = array ('hersteller 1' , 'hersteller 2'); $herste

我想构建html表单,它将显示数据库中的数据。我想在表单的操作文件中修改这些

但是我的构造不起作用

这是我的代码:

            <?php
            //include 'readHersteller.php';
            //$hersteller = $resultIDs;
            $hersteller = array ('hersteller 1' , 'hersteller 2'); 
            $herstellerAnzahl = count($hersteller);
            echo '

                <div class="container">
                    <form action="actionHandler.php" method="post">
                        <h2>Hersteller wählen</h2>
                        <p>Wählen Sie hier den hersteller, dessen Produktlieferzeit verändert werden soll.</p>
                        <div class="form-group">
                            <label for="sel1">Wählen Sie hier einen der '.$herstellerAnzahl.' Hersteller aus:</label>
                            <select class="form-control" id="sel1">
                                ';
                                foreach ($hersteller as &$value){
                                echo '<option>'.$value.'</option>';
                                }
            echo '
                            </select>
                        </div>
                    </div> 
                    <h2> Geben Sie die gewünschte Lieferzeit ein: </h2>
                    <textarea class="form-control" rows="1" id="lieferzeit">Maßanfertigung in 1-3 Wochen bei Ihnen</textarea>
                    <br>
                </form> 
                <button type="submit" class="btn btn-primary btn-lg value="Submit">Absenden</button>
            ';

        ?>

我选择了这个echo,因为我需要foreach循环在表单中显示我的数组,然后我需要从textarea获取值并将两者提交到actionHandler.php

那不行,因为我的回声把表格分开了

问题:如何在表单中更好地显示php数组,以便能够创建一个表单

你需要改变

foreach ($hersteller as &$value){
   echo '<option>'.$value.'</option>';
}
foreach($hersteller as&$value){
回显“.$value.”;
}

foreach($hersteller作为$value){
回显“.$value.”;
}
PHP无法读取&$variablename之类的变量。我建议您获得一个IDE来突出显示这些错误。Atom对于初学者来说是个不错的选择

德语: 《士兵》杂志编辑wie Atom anlegen,dieser zeigt主编schnell solch oberflächlichen Erros。我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们,我的孩子们


MFG

我将向您推荐一个类似的解决方案,但它将完全使用
,这样您就不会陷入转义
'
的问题,在这些情况下,转义可能会更加困难

此外,还需要注意以下几点:

  • 您的标签嵌套不好
  • 您的
    标记格式不正确,您尚未关闭类值(
  • 除非添加相应的表单属性,否则
    应该位于表单块内
  • 您正在使用foreach
    和$value
    中的引用,这是不必要的
  • 建议重写:

    <?php
      //include 'readHersteller.php';
      //$hersteller = $resultIDs;
      $hersteller = array(
        'hersteller 1',
        'hersteller 2'
      );
      $herstellerAnzahl = count($hersteller);
    ?>
    <div class="container">
      <form action="actionHandler.php" method="post">
        <h2>Hersteller wählen</h2>
        <p>Wählen Sie hier den hersteller, dessen Produktlieferzeit verändert werden soll.</p>
        <div class="form-group">
          <label for="sel1">Wählen Sie hier einen der <?php echo $herstellerAnzahl; ?> Hersteller aus:</label>
          <select class="form-control" id="sel1">
          <?php
            foreach ($hersteller as $value) {
              echo '<option>' . $value . '</option>';
            }
          ?>
          </select>
        </div>
        <h2> Geben Sie die gewünschte Lieferzeit ein: </h2>
        <textarea class="form-control" rows="1" id="lieferzeit">Maßanfertigung in 1-3 Wochen bei Ihnen</textarea>
        <button type="submit" class="btn btn-primary btn-lg" value="Submit">Absenden</button>      
      </form> 
    </div><!-- This should be here. -->
    
    
    赫斯特勒·沃伦
    她是赫斯特勒先生,她是一名独立的生产商

    您在澳大利亚的赫斯特勒先生那里: 你的名字是什么 1-3沃臣北伊涅马ß安富里村 阿本登

    此外,表单输入元素上没有名称属性。因此当前不会提交任何数据。

    首先生成字符串,然后打印
    echo
    it
    foreach($hersteller as&$value){echo'.$value.';
    这是什么
    &$value
    它应该是
    $value
    为什么给定的代码不应该工作?您第二次忘记了回显$value:echo'.$value.';如果您觉得舒服的话,这种编码风格没有什么特别的错误。生成的html只是一种形式。有两个问题:您的按钮位于窗体外部。并且您的窗体元素缺少名称属性。这实际上是可行的,它将值作为引用传递,但如果您想从循环中更改
    $hersteller
    数组中的
    $value
    ,则只需这样做。两个代码示例之间的区别是什么?输出应该完全是sameYes,这是一个不好的建议。谢谢你的回答:)但是我的代码有效,@krom的回答是相同的,也许这种方法只在更高的php版本中可用?@Progrock-Woah…谢谢。看起来你可以用更好的方法来回答…
    :D
    我会把它们加起来…或者如果你想编辑我的回答,我给你所有的权利…
    :D
    非常感谢,这就是答案:)我现在很高兴:)但是有什么显著的区别吗?O.O只有(“”?@Rudi不仅如此。很多。
    :)
    <?php
      //include 'readHersteller.php';
      //$hersteller = $resultIDs;
      $hersteller = array(
        'hersteller 1',
        'hersteller 2'
      );
      $herstellerAnzahl = count($hersteller);
    ?>
    <div class="container">
      <form action="actionHandler.php" method="post">
        <h2>Hersteller wählen</h2>
        <p>Wählen Sie hier den hersteller, dessen Produktlieferzeit verändert werden soll.</p>
        <div class="form-group">
          <label for="sel1">Wählen Sie hier einen der <?php echo $herstellerAnzahl; ?> Hersteller aus:</label>
          <select class="form-control" id="sel1">
          <?php
            foreach ($hersteller as $value) {
              echo '<option>' . $value . '</option>';
            }
          ?>
          </select>
        </div>
        <h2> Geben Sie die gewünschte Lieferzeit ein: </h2>
        <textarea class="form-control" rows="1" id="lieferzeit">Maßanfertigung in 1-3 Wochen bei Ihnen</textarea>
        <button type="submit" class="btn btn-primary btn-lg" value="Submit">Absenden</button>      
      </form> 
    </div><!-- This should be here. -->