Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.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
Php 多数组形式赢得';t存储变量_Php_Arrays_Forms_Multidimensional Array - Fatal编程技术网

Php 多数组形式赢得';t存储变量

Php 多数组形式赢得';t存储变量,php,arrays,forms,multidimensional-array,Php,Arrays,Forms,Multidimensional Array,我有一个提交到update.php的表单,它应该接受POST变量并将它们存储在另一个文件中 表格: <fieldset> <legend>Proficiencies:</legend> <span>Name:</span> <span>exp:</span> <span>Rank:</span><br/> <?php

我有一个提交到update.php的表单,它应该接受POST变量并将它们存储在另一个文件中

表格:

<fieldset>
        <legend>Proficiencies:</legend>
        <span>Name:</span> <span>exp:</span> <span>Rank:</span><br/>
        <?php
             $x = 0;
             if ($proficiencies) {
                foreach ($proficiencies as $proficiency) {
                        echo '<input type="text" name="proficiencies['.$x.'][\'name\']" value="'.$proficiency["name"].'"/>';
                        echo ' <input type="text" name="proficiencies['.$x.'][\'exp\']" value="'.$proficiency["exp"].'"/>';
                        echo ' <input type="text" name="proficiencies['.$x.'][\'rank\']" value="'.$proficiency["rank"].'"/>';
                        echo '<br/>';
                        $x++;
               }
            }
           echo '<input type="text" name="proficiencies['.$x.'][\'name\']"/>';
           echo ' <input type="text" name="proficiencies['.$x.'][\'exp\']"/>';
           echo ' <input type="text" name="proficiencies['.$x.'][\'rank\']"/>';
       ?>

</fieldset>

熟练程度:
姓名:exp:Rank:
update.php:

<?php
echo 'making changes';
$user = fopen('sheets/'.$_COOKIE['username'].'.php', 'w+');
fwrite ($user, '<?php
$proficiencies = array(
');
foreach ($_POST['proficiencies'] as $proficiency) {
    if ($proficiency["name"]) {
        fwrite ($user, '    array(
        "name" => "'.$proficiency["name"].'",
        "exp" => "'.$proficiency["exp"].'",
        "rank" => "'.$proficiency["rank"].'",
    ),
'
        );
    }
}
fwrite ($user, ');
?>');
fclose($user);
?>


我尝试了很多不同的方法,但在html表单名称中,它就是不起作用,您不允许使用引号

改变

echo '<input type="text" name="proficiencies['.$x.'][\'name\']" value="'.$proficiency["name"].'"/>';
echo ' <input type="text" name="proficiencies['.$x.'][\'exp\']" value="'.$proficiency["exp"].'"/>';
echo ' <input type="text" name="proficiencies['.$x.'][\'rank\']" value="'.$proficiency["rank"].'"/>';
echo';
回声';
回声';
致:

echo';
回声';
回声';
这应该很好

更正:您可以在表单名称中使用引号,但它会像它的名称一样进行携带,因此在$\u POST['proficiencies']中应该有类似$proficiency[“'name'”]的键-注意双引号中的单引号:p
echo '<input type="text" name="proficiencies['.$x.'][name]" value="'.$proficiency["name"].'"/>';
echo ' <input type="text" name="proficiencies['.$x.'][exp]" value="'.$proficiency["exp"].'"/>';
echo ' <input type="text" name="proficiencies['.$x.'][rank]" value="'.$proficiency["rank"].'"/>';