javascript - how to get(call) dynamically generated variable value to save in (mysql) database using php -


i trying save value of dynamically generated checkbox, label , select tag in mysql database using php in tags retrieving value different database , trying save data of checked field label value , selected option value, not able it, please suggest me doing wrong.

<script language="javascript">                 function getmatchplayer1(mid)                 {                     window.location="?mid="+mid;                 }                  </script>         </head>         <?php          $host="localhost";                          // host name      $username="root";                       // mysql username      $password="";                           // mysql password      $db_name="test";                    // database name       // connect server , select database.     mysql_connect("$host", "$username", "$password")or die("cannot connect");       // select database on server     mysql_select_db("$db_name")or die("cannot select db");           if(isset($_post['saveteam'])){     $tmnma = $_post['teamnamea'];     $tmnmb = $_post['teamnameb'];     $mch_id = $_post['mtch_id'];     $chk_id = $_post['$chkid'];     $cric_nm = $_post['$ply_nm'];     $chk_rnk = $_post['$chkrnk'];       $sqlbat = "insert board(cricketer_id, status,runs,sixes,fifty,hundred,total_score,total_points)values('$cric_nm', 'np','0','0','0','0','0','0')";      $retval = mysql_query( $sqlbat );     if(! $retval )     {       die('could not update data: ' . mysql_error());     }     echo "updated data successfully\n";      }             $sql=mysql_query( "select * tbl_info limit 5");              $cric_id = $resultmp['player_id'];          ?>     <body style="align:center">     <form method="post" id="form1" name="form1" action="">             <div style="width:850px; margin-left:55px; text-align:right">                 <input type="submit" id="saveteam" name="saveteam" value="     save     " />             </div>     <table align="center" width="900" height="auto" style="border-top:1px solid #cccccc;border-right:1px solid #cccccc; border-left:1px solid #cccccc; cellspacing:0px; cellpadding:0px;">     <tr style="border:1px solid #cccccc">       <td width="450" style="border:1px solid #cccccc"> today's match:-&nbsp;&nbsp;&nbsp;         <select name="mtch_id" id="mtch_id" onchange="getmatchplayer1(this.value)">           <option> select team </option>           <?php                     $i=1;                     $sqlm=mysql_query("select * t_match limit 5");                     while ($resultm=mysql_fetch_array($sqlm))                     {                         $mtch=$resultm['match_no'];                         echo "<option id='".$i."' value='".$mtch."'>";                             echo $mtch;                         echo "</option>";                     $i++;}                 ?>         </select></td>       <td width="450" style="border:1px solid #cccccc">                     <?php                                       $j=1;                                     if (isset($_request['mid']))                                     {                                         $mid=$_request['mid'];                                     }                                     $sqlm1=mysql_query("select * t_match match_no = '$mid'");                                     while ($resultm1=mysql_fetch_array($sqlm1)){                                         $mtch=$resultm1['match_no'];                                         $mtch1=$resultm1['team1'];                                         $mtch2=$resultm1['team2'];                                         $chkid = 'a'.$a;                         ?>               </td>     </tr>     <tr style="border:1px solid #cccccc">       <td style="text-align:center; border:1px solid #cccccc">         <?php              echo "team - ".$mtch1;          ?>       </td>       <td style="text-align:center; border:1px solid #cccccc">         <?php              echo "team - ".$mtch2;              }         ?>       </td>     </tr>      <tr>       <td height="auto" colspan="2">         <div id="update" style="width:900px; height:24px;">         <div style="float:left; width:450px; height:24px;">         <?php                     $a=1;                      $b=2;                     $k=1;                     $sqlmp=mysql_query("select * tbl_info player_team = '$mtch1' limit 5");                     while ($resultmp=mysql_fetch_array($sqlmp)){                       echo "<script language='javascript'>      //on checked disabled enabled condition      function codenamea".$a."()     {         if (document.form1.a".$a.".checked)         {             document.form1.b".$a.".disabled = false;         }         else         {             document.form1.b".$a.".disabled = true;         }     }      /*condition limit checked 11 team a*/      //initial checkcount of 0     var checkcount = 0      //maximum number of allowed checked boxes     var maxchecks = 11          function setchecksa".$a."(obj)         {             //increment/decrement checkcount             if (obj.checked)             {                 checkcount=checkcount+1             }             else             {                 checkcount=checkcount-1             }             //if checked 11th box, uncheck box, decrement checkcount , pop alert             if (checkcount>maxchecks)             {                 obj.checked=false                 document.form1.b".$a.".disabled=true;                 checkcount=checkcount-1                 alert('you may choose '+maxchecks+' options')             }         }         //-->         </script>";          ?>                  <div style="float:left; width:80%; height:24px; border:1px solid #cccccc">                     <input onclick='codenamea<?php echo $a; ?>(), setchecksa<?php echo $a; ?>(this)' type='checkbox' id='a<?php echo $a; ?>' name='a<?php echo $a; ?>' value='<?php echo $resulttmp['player_id']; ?>' /><input type="hidden" id="lt<?php $a; ?>" name="lt<?php $a; ?>" value="<?php echo $resulttmp['player_name']; ?>" />&nbsp;&nbsp;&nbsp;<?php echo $resultmp ['player_name']; ?>                 </div>                 <div style="float:right; width:19%; height:24px; border:1px solid #cccccc">                     <select disabled='disabled' id='b<?php echo $a; ?>' name='b<?php echo $a; ?>' style='width:100%;'>             <option>                 - -             </option>             <option value='1'>                 1             </option>             <option value ='2'>                 2             </option>             <option value='3'>                 3             </option>             <option value='4'>                 4             </option>             <option value='5'>                 5             </option>             <option value='6'>                 6             </option>             <option value='7'>                 7             </option>             <option value='8'>                 8             </option>             <option value='9'>                 9             </option>             <option value='10'>                 10             </option>             <option value='11'>                 11             </option>           </select>                  </div>       <?php                   $a++;          $b++;      }     ?>     </div>       </td>     </tr>     </table>     </form> 

if understood correctly, generating names of inputs dinamically, using $a increment variable. reason cant recalculate names when post not able posted values. can resolve in many ways, 1 generate input names way:

<input type="checkbox" name="blah[$a]"/> <select name="bleh[$a]">...</select> 

this result in post array so:

array(      "blah" => array($a => valueofcheckbox),     "bleh" => array($a => valueofselect) ) 

that can parse simple foreach

foreach ($_post["blah"] $a => $value) {     ... }  foreach ($_post["bleh"] $a => $value) {     ... } 

i dont quite understand enable/disable logic, said before, thats messy code, should know disabled fields not posted.

ps: code posted pseudo-code.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -