回声未知的文本字段

时间:2016-03-12 17:24:00

标签: php html text echo textfield

好的,所以我运行这段代码,我在第68行得到一个错误,这是在第二个php段,它从文本字段中获取信息,其中说:

Notice: Undefined index: fieldno0 in C:\wamp\www\addform.php on line 68

任何想法在这里出了什么问题?我一直在搞乱这段代码,但我无法弄清楚为什么我无法从文本字段中获取信息。

<!DOCTYPE html>
<html>
<body>

<?php
    $nof="fieldno";
    $nos="Type";

    $servername = "localhost";
    $username = "root";
    $password = "";
    // Create connection
    $conn = new mysqli($servername, $username, $password,"vaccinations");

            echo "<form action='addform.php' method='POST'>
<button type='submit' name='subform'>Submit Form</button><br>
<input type='text' placeholder='Number of fields' name='fieldno'/><br>
<input type='text' placeholder='Name of Form' name='form'/>
<button type='submit' name= 'submit' >Create fields</button> <br>
</form><br>";


    $query= $conn->query("SELECT * FROM element_types");
    $data = array();
    while($rows = $query->fetch_assoc()){
        $data[] = $rows;
    }


    if(isset($_POST['submit'])){
         $fields = $_POST['fieldno'];
         $FormName = $_POST['form'];

         if($fields && $FormName){
        $conn->query("INSERT INTO `vaccinations`.`forms` (`Name`, `author`, `number_of_elements`) VALUES ('$FormName', '5', '$fields');");}

        echo "<form action='addform.php' method='POST'>";

        for ($i=0; $i<$fields; $i++) {  

            echo "<input type='text' placeholder='Enter name of field$i' name='$nof$i'/>";
            echo "$nof$i";
            echo "<select name='$nos$i'>";
            for($x=0;$x<sizeof($data);$x++){
                echo "<option value=".$data[$x]['id'].">".$data[$x]['name']."</option>";
                }
                echo "</select><br></form><br>";
            }           
    }

?>

<?php
if((isset($_POST['subform'])) ){
            $fields=$conn->query("SELECT number_of_elements FROM forms WHERE id IN (SELECT MAX(id) FROM forms)");

            while($rows = $fields->fetch_assoc()){
                    $data[] = $rows;
            }

            $data[0] = (int)$data[0];

            $fields=$data;

            echo("WHADDUP");

                for($y=0;$y<1;$y++){
                    $fieldname = $_POST["$nof$y"];
                    echo $fieldname;
                    //$IorderInForm = ('$y-1');
                    //$selectOption = $_POST["$nos$y"]; 

                    //$insert=$conn->query("INSERT INTO `vaccinations`.`form_elements`
                    // (`form_id`, `field_number_in_form`, `element_type_id`, `field_name`)
                     // VALUES ('$formId', '$IorderInForm', '$selectOption', '$Ifieldname')");
            }
        }   
?>

</body>
</html>

0 个答案:

没有答案