Created
July 26, 2016 02:32
-
-
Save MahbbRah/1e894ee43fe8d010174716131a4ff816 to your computer and use it in GitHub Desktop.
multiple insert in single submission
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| ob_start(); | |
| include('../db_config.php'); | |
| $db = database::getInstance(); | |
| $sql = "SELECT * FROM computer"; | |
| $result = $db->dbc->query($sql); | |
| $count = $result->rowCount(); | |
| ?> | |
| <table width="500" border="0" cellspacing="1" cellpadding="0"> | |
| <form name="form1" method="post" action=""> | |
| <tr> | |
| <td> | |
| <table width="500" border="0" cellspacing="1" cellpadding="0"> | |
| <tr> | |
| <td align="center"><strong>roll</strong></td> | |
| <td align="center"><strong>S Name</strong></td> | |
| <td align="center"><strong>F name</strong></td> | |
| <td align="center"><strong>M name</strong></td> | |
| </tr> | |
| <?php | |
| while($rows=$result->fetch()){ | |
| ?> | |
| <tr> | |
| <td align="center"> | |
| <? $id[]=$rows['roll']; ?><? echo $rows['roll']; ?> | |
| </td> | |
| <td align="center"> | |
| <input name="name[]" type="text" id="name" value="<? echo $rows['s_name']; ?>"> | |
| </td> | |
| <td align="center"> | |
| <input name="lastname[]" type="text" id="lastname" value="<? echo $rows['f_name']; ?>"> | |
| </td> | |
| <td align="center"> | |
| <input name="email[]" type="text" id="email" value="<? echo $rows['m_name']; ?>"> | |
| </td> | |
| </tr> | |
| <?php | |
| } | |
| ?> | |
| <tr> | |
| <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> | |
| </tr> | |
| </table> | |
| </td> | |
| </tr> | |
| </form> | |
| </table> | |
| <?php | |
| // Check if button name "Submit" is active, do this | |
| if(isset($_POST['Submit'])){ | |
| for($i=0;$i<$count;$i++){ | |
| $name = $_POST['name']; | |
| $f_name = $_POST['lastname']; | |
| $m_name = $_POST['email']; | |
| $total[$i] = $name[$i] + $f_name[$i]; | |
| $sql1="UPDATE computer SET s_name='$name[$i]', f_name='$f_name[$i]', m_name='$total[$i]' WHERE roll='$id[$i]'"; | |
| $result1=$db->dbc->query($sql1); | |
| } | |
| if ($result1) { | |
| echo 'success'; | |
| header('Location: pdo.php'); | |
| } | |
| else { echo "Error";} | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment