Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if(!isset($_SESSION["sess_user"])){
- header("location:login.php");
- } else {
- ?>
- <!doctype html>
- <html>
- <head>
- <script>
- function showUser(str) {
- if (str=="") {
- document.getElementById("txtHint").innerHTML="";
- return;
- }
- if (window.XMLHttpRequest) {
- // code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- } else { // code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function() {
- if (this.readyState==4 && this.status==200) {
- document.getElementById("txtHint").innerHTML=this.responseText;
- }
- }
- xmlhttp.open("GET","modifymain.php?q="+str,true);
- xmlhttp.send();
- }
- </script>
- <title>Login</title>
- <style>
- body{
- margin-top: 100px;
- margin-bottom: 100px;
- margin-right: 150px;
- margin-left: 80px;
- background-color: azure ;
- color: palevioletred;
- font-family: verdana;
- font-size: 100%
- }
- h1 {
- color: indigo;
- font-family: verdana;
- font-size: 100%;
- }
- h3 {
- color: indigo;
- font-family: verdana;
- font-size: 100%;
- }
- </style>
- </head>
- <body>
- <?php
- $databaseHost="localhost";
- $databaseUser="root";
- $databasePassword="root@123";
- $databaseName="sms";
- $con=mysqli_connect($databaseHost,$databaseUser,$databasePassword) or die ('Connection Error');
- mysqli_select_db($con,"sms") or die ('Database Error');
- ?>
- <span style="font-family:Georgia,'Times New Roman','Bitstream Charter',Times,serif;font size: small"><span style "line-height: 19px"> </span> </span> <?php ?>
- <form name="frmdropdown" method="post" action="modify.php">
- <center>
- <h2 align="center">DATA</h2>
- <strong> Select Operator : </strong>
- <select name="operator" onchange="showUser(this.value)">
- <option value=" ">--------ALL--------</option>
- <?php
- $query="Select DISTINCT operator_name from operator_details"; // Always set query first.
- $result=mysqli_query($con,$query); // Next, run the query in db using mysqli_query
- while($r=mysqli_fetch_row($result)) // Fetching multiple rows ( only possible if parameter is result of a query
- {
- echo "<option value='$r[0]'> $r[0] </option>"; // Printing the result
- }
- //echo $str;
- //echo this.value;
- //$_SESSION['myvar'] = $str;
- //echo $_SESSION['myvar'];
- ?>
- </select>
- //<div id="txtHint"><b> Operator will be listed here.</b></div>
- <br> </br>
- <form name="peaknopeak" method="post" action="modify.php">
- PEAK HOUR: <input type="text" name="peak"/>
- echo "e.g. 7-7";
- <br></br>
- NON-PEAK HOUR: <input type="text" name="nopeak"/>
- echo "e.g. 1-2";
- <br></br>
- <input type="submit" value="OK" name="submit"/>
- <br> </br>
- <table border="1">
- <tr align="center">
- </tr>
- <?php
- if(isset($_POST["submit"])){
- if(!empty($_POST['peak']) && !empty($_POST['nopeak'])) {
- $peak=$_POST['peak'];
- $nopeak=$_POST['nopeak'];
- //echo $peak;
- //echo $nopeak;
- $operator=$_SESSION["main"];
- $con=mysqli_connect('localhost','root','root@123') or die(mysql_error());
- mysqli_select_db($con,'sms');
- $query="SELECT * FROM operator_details WHERE operator_name='".$operator."'";
- if($result=mysqli_query($con,$query))
- { $numrows=mysqli_num_rows($result);
- printf("Result set has %d rows.\n",$numrows);
- //mysqli_free_result($result);
- if($result)
- {
- $sql="UPDATE sms_table SET peak_hour = '$peak', non_peak_hour = '$nopeak' WHERE operator_name='$operator'";
- //echo "updated both peak and non-peak";
- $result=mysqli_query($con,$sql);
- if($result){
- echo "Entry Updated Successfully";
- } else {
- echo "Failure!";
- }
- } else {
- echo "That operator already exists! Please try again with another.";
- }
- }
- }else {
- echo "All fields are required!";
- }
- }
- mysqli_close($con);
- ?>
- <?php
- }
- ?>
- </table>
- </center>
- </form>
- <h2><a href="login.php"><center>Main Page</center></a></h2>
- </body>
- </html>
Add Comment
Please, Sign In to add comment