Guest User

Untitled

a guest
Feb 16th, 2018
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. <?php
  2.  
  3. $DatabaseServer = "localhost";
  4. $DatabaseUsername = "root";
  5. $DatabasePassword = "root";
  6. $DatabaseName = "demo";
  7.  
  8. $Connection = mysqli_connect($DatabaseServer, $DatabaseUsername, $DatabasePassword, $DatabaseName);
  9.  
  10. if ($Connection === false) {
  11. die("ERROR: Could not connect. " . mysqli_connect_error());
  12. }
  13.  
  14. $sqlusers = "select * from user";
  15. $result = mysqli_query($Connection, $sqlusers);
  16. echo "<form method='POST'>";
  17. while($rowuser = mysqli_fetch_array($result)){
  18. $user = $rowuser['FirstName'];
  19.  
  20.  
  21. echo "<input type='text' name='firstName' value='$user' readonly>";
  22. echo "<select name='attendanceType'>";
  23.  
  24. $sqltype = "select * from attendancetype";
  25. $resultaType = mysqli_query($Connection, $sqltype);
  26. while($rowtype = mysqli_fetch_array($resultaType)){
  27. echo "<option>";
  28. echo $rowtype['name'];
  29. echo "</option>";
  30. }
  31.  
  32. echo "</select>";
  33. echo "<br>";
  34.  
  35. }
  36. echo "<input type='submit' name='submit' value='submit'>";
  37. echo "</form>";
  38. ?>
  39.  
  40. INSERT INTO `user` (`UserID`, `FirstName`, `LastName`, `Email`, `Password`, `City`) VALUES
  41. (7, 'Rahul', 'Rajshekaran', 'Rahul@zzz.xxx', 'Rahul@123', 'Pune'),
  42. (8, 'Mahesh', 'Krishna', 'Mahesh@xxx.xxx', 'Mahesh@123', 'Delhi');
  43.  
  44. INSERT INTO `attendancetype` (`attendanceTypeID`, `name`) VALUES
  45. (0001, 'Present'),
  46. (0002, 'Absent');
  47.  
  48. $i = 0;
  49. while($rowuser = mysqli_fetch_array($result)){
  50. $user = $rowuser['FirstName'];
  51.  
  52.  
  53. echo "<input type='text' name='firstName[".$i."]' value='$user' readonly>";
  54. echo "<select name='attendanceType[".$i."]'>";
  55.  
  56. $sqltype = "select * from attendancetype";
  57. $resultaType = mysqli_query($Connection, $sqltype);
  58. while($rowtype = mysqli_fetch_array($resultaType)){
  59. echo "<option>";
  60. echo $rowtype['name'];
  61. echo "</option>";
  62. }
  63.  
  64. echo "</select>";
  65. echo "<br>";
  66. $i++;
  67. }
  68.  
  69. <?php
  70. foreach($_POST['firstName'] as $i => $user) {
  71. $sql = "insert into table set attendance_type = '".escapeFunction($_POST['attendanceType'][$i])."' where user='".escapeFunction($user)."'";
  72. mysql_query($Connection, $sql);
  73. }
  74. ?>
Add Comment
Please, Sign In to add comment