php - how to access form data using post in loop -


i trying access data form field dynamically created , store db.i don't know how that.i tried many ways didn't worked.please me.thank reading this.....

    <html lang="en">     <head>     <title>toggle</title>     <meta http-equiv="content-type" content="text/html; charset=utf-8">      <?php     $link = mysql_connect('localhost', 'root', '');     if (!$link) {         die('could not connect mysql server: ' . mysql_error());     }     $dbname = 'attendance';     $db_selected = mysql_select_db($dbname, $link);     if (!$db_selected) {         die("could not set $dbname: " . mysql_error());     }     $res = mysql_query('select * student', $link);     if(isset($_post["submit"]))     {         $name=$_post['student'];         echo $name;     }     ?>     <script type="text/javascript">     function change(obj) {     var tr=obj.parentnode; // may change depending on html used     tr.style.backgroundcolor=(obj.checked)? 'green' : 'red';     }     </script>     <style type="text/css">     .nochange, tr {background-color:green;}      </style>     </head>     <body onload="change(this)">     report attendance     <table border="1" cellspacing="2" cellpadding="5" summary="">     <form name="myform" action="" method="post">     <?php while ($row = mysql_fetch_assoc($res)){       echo "<tr class='nochange'><td><input type='checkbox' name='student' value='" . $row['stu_id'] . "' checked style='background:#f00;' onclick='change(this);'>" . $row['stu_name'] . "<br />"."</td></tr>";     }?>     <input type="submit" name="submit" value="submit"/>     </form>     </table>     </body>     </html> 

make checkbox array

<html lang="en"> <head> <title>toggle</title> <meta http-equiv="content-type" content="text/html; charset=utf-8">  <?php $link = mysql_connect('localhost', 'root', ''); if (!$link) {     die('could not connect mysql server: ' . mysql_error()); } $dbname = 'attendance'; $db_selected = mysql_select_db($dbname, $link); if (!$db_selected) {     die("could not set $dbname: " . mysql_error()); } $res = mysql_query('select * student', $link); if(isset($_post["submit"])) {     //here goes array     for($i=0;$i<count($_post['student']);$i++)     {         $name=$_post['student'][$i];         echo $name;     } } ?> <script type="text/javascript"> function change(obj) { var tr=obj.parentnode; // may change depending on html used tr.style.backgroundcolor=(obj.checked)? 'green' : 'red'; } </script> <style type="text/css"> .nochange, tr {background-color:green;}  </style> </head> <body onload="change(this)"> report attendance <table border="1" cellspacing="2" cellpadding="5" summary=""> <form name="myform" action="" method="post"> <?php while ($row = mysql_fetch_assoc($res)){   echo "<tr class='nochange'><td><input type='checkbox' name='student[]' value='" . $row['stu_id'] . "' checked style='background:#f00;' onclick='change(this);'>" . $row['stu_name'] . "<br />"."</td></tr>"; }?> <input type="submit" name="submit" value="submit"/> </form> </table> </body> </html> 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -