Guest User

Untitled

a guest
Jun 27th, 2017
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if(!isset($_SESSION["sess_user"])){
  4. header("location:login.php");
  5. } else {
  6. ?>
  7. <!doctype html>
  8. <html>
  9. <head>
  10. <script>
  11. function showUser(str) {
  12. if (str=="") {
  13. document.getElementById("txtHint").innerHTML="";
  14. return;
  15. }
  16. if (window.XMLHttpRequest) {
  17. // code for IE7+, Firefox, Chrome, Opera, Safari
  18. xmlhttp=new XMLHttpRequest();
  19. } else { // code for IE6, IE5
  20. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  21. }
  22. xmlhttp.onreadystatechange=function() {
  23. if (this.readyState==4 && this.status==200) {
  24. document.getElementById("txtHint").innerHTML=this.responseText;
  25. }
  26. }
  27. xmlhttp.open("GET","modifymain.php?q="+str,true);
  28. xmlhttp.send();
  29. }
  30. </script>
  31. <title>Login</title>
  32. <style>
  33. body{
  34.  
  35. margin-top: 100px;
  36. margin-bottom: 100px;
  37. margin-right: 150px;
  38. margin-left: 80px;
  39. background-color: azure ;
  40. color: palevioletred;
  41. font-family: verdana;
  42. font-size: 100%
  43.  
  44. }
  45. h1 {
  46. color: indigo;
  47. font-family: verdana;
  48. font-size: 100%;
  49. }
  50. h3 {
  51. color: indigo;
  52. font-family: verdana;
  53. font-size: 100%;
  54. }
  55. </style>
  56. </head>
  57. <body>
  58.  
  59. <?php
  60. $databaseHost="localhost";
  61. $databaseUser="root";
  62. $databasePassword="root@123";
  63. $databaseName="sms";
  64. $con=mysqli_connect($databaseHost,$databaseUser,$databasePassword) or die ('Connection Error');
  65. mysqli_select_db($con,"sms") or die ('Database Error');
  66. ?>
  67.  
  68. <span style="font-family:Georgia,'Times New Roman','Bitstream Charter',Times,serif;font size: small"><span style "line-height: 19px"> </span> </span> <?php ?>
  69.  
  70. <form name="frmdropdown" method="post" action="modify.php">
  71. <center>
  72. <h2 align="center">DATA</h2>
  73. <strong> Select Operator : </strong>
  74.  
  75. <select name="operator" onchange="showUser(this.value)">
  76. <option value=" ">--------ALL--------</option>
  77. <?php
  78. $query="Select DISTINCT operator_name from operator_details"; // Always set query first.
  79. $result=mysqli_query($con,$query); // Next, run the query in db using mysqli_query
  80. while($r=mysqli_fetch_row($result)) // Fetching multiple rows ( only possible if parameter is result of a query
  81. {
  82. echo "<option value='$r[0]'> $r[0] </option>"; // Printing the result
  83. }
  84. //echo $str;
  85. //echo this.value;
  86. //$_SESSION['myvar'] = $str;
  87. //echo $_SESSION['myvar'];
  88. ?>
  89. </select>
  90. //<div id="txtHint"><b> Operator will be listed here.</b></div>
  91.  
  92. <br> </br>
  93. <form name="peaknopeak" method="post" action="modify.php">
  94. PEAK HOUR: <input type="text" name="peak"/>
  95. echo "e.g. 7-7";
  96. <br></br>
  97. NON-PEAK HOUR: <input type="text" name="nopeak"/>
  98. echo "e.g. 1-2";
  99. <br></br>
  100. <input type="submit" value="OK" name="submit"/>
  101. <br> </br>
  102. <table border="1">
  103. <tr align="center">
  104. </tr>
  105. <?php
  106. if(isset($_POST["submit"])){
  107. if(!empty($_POST['peak']) && !empty($_POST['nopeak'])) {
  108. $peak=$_POST['peak'];
  109. $nopeak=$_POST['nopeak'];
  110. //echo $peak;
  111. //echo $nopeak;
  112. $operator=$_SESSION["main"];
  113. $con=mysqli_connect('localhost','root','root@123') or die(mysql_error());
  114. mysqli_select_db($con,'sms');
  115.  
  116. $query="SELECT * FROM operator_details WHERE operator_name='".$operator."'";
  117.  
  118. if($result=mysqli_query($con,$query))
  119. { $numrows=mysqli_num_rows($result);
  120. printf("Result set has %d rows.\n",$numrows);
  121. //mysqli_free_result($result);
  122.  
  123. if($result)
  124. {
  125. $sql="UPDATE sms_table SET peak_hour = '$peak', non_peak_hour = '$nopeak' WHERE operator_name='$operator'";
  126. //echo "updated both peak and non-peak";
  127. $result=mysqli_query($con,$sql);
  128. if($result){
  129. echo "Entry Updated Successfully";
  130. } else {
  131. echo "Failure!";
  132. }
  133.  
  134. } else {
  135. echo "That operator already exists! Please try again with another.";
  136. }
  137. }
  138. }else {
  139. echo "All fields are required!";
  140. }
  141. }
  142. mysqli_close($con);
  143.  
  144. ?>
  145.  
  146.  
  147. <?php
  148. }
  149. ?>
  150. </table>
  151. </center>
  152. </form>
  153.  
  154. <h2><a href="login.php"><center>Main Page</center></a></h2>
  155. </body>
  156. </html>
Add Comment
Please, Sign In to add comment