2016-03-25 15 views
0

ben POST değişkenler alıp başka bir dosyaçoklu dizi biçimi değişkenleri saklamaz

formu saklamanız gereken update.php teslim olan bir form var:

<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> 

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); 
?> 

bunu yapmanın birçok farklı yolu denedim ama sadece html içinde

cevap

0

çalışmayacak

+0

** Düzeltme ince olmalıdır

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"].'"/>'; 

: ** Form adında tırnak kullanabilirsiniz formu isimleri

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"].'"/>'; 

için tırnak

değişiklik kullanmalarına izin verilmez ancak $ _POST ['proficencies'] 'de olduğu gibi bu isimle taşınacak, $ ustalık ["' name '"] gibi tuşlar olmalı. - Çift tırnakların içindeki tek tırnaklara dikkat edin: P – zedling

+0

. Bu çok yardımcı oldu – KlingonDragon