PHP POST ARRAY to json_encode -


i want use json store value mysql cuz making quiz , there many answers. doesn't go well. please tell me what's wrong.thx!

<form  method="post" action="resultme.php">      <h4>   q1 </h4>       <input name="a[0][]" type="radio"  value="1" /><span>yes</span>        <input name="a[0][]" type="radio"  value="2" /><span>maybe</span>        <input name="a[0][]" type="radio"  value="3" /><span>no</span>         <h4>   q2 </h4>         <input name="a[1][]" type="radio"  value="1" /><span>yes</span>           <input name="a[1][]" type="radio" value="2" /><span>maybe</span>           <input name="a[1][]" type="radio" value="3" /><span>no</span>      <h4> q3 </h4>         <li class="ji">language</li>         <li><input name="a[2][]" type="checkbox"  value="11" /><span>english</span></li>         <li><input name="a[2][]" type="checkbox"  value="12" /><span>chiness</span></li>           <li class="ji">sport</li>           <li><input name="a[2][]" type="checkbox" value="21" /><span>swim</span></li>          </ul> <input type="submit" value="click" name="submit" /> 

how post thing? here thought below each answer can json {} it' no use.

$ans   =array(  "q1"=> $_post['a[0]'],         "q2"=> $_post['a[1]'],         "q3"=> $_post['a[2]'],             ) print_r json_encode( $ans ); 

  1. to debug, print_r($_post); after submit see structure
  2. try

    $ans = array();

    foreach($_post['a'] $idx => $answer)

    {

    $ans['q'.($idx+1)] = $anwser;

    }

    $ans = json_encode( $ans );


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -