SHARE
TWEET

Untitled

a guest Dec 13th, 2016 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    <html>
  2.  
  3.    <head>
  4.  
  5.      <title>Police Traffic Database</title>
  6.  
  7.    </head>
  8.  
  9.    <body>
  10.    
  11.     <form action="mersey.cs.nott.ac.uk/~psxrjt/policeDBaddINCIDENT.php" method="get">
  12.          <input type="button" name="pressed" value="File Incident Report">
  13.     </form>
  14.    
  15.    <h1> Add Vehicle</h1>
  16.    
  17.     <form method="POST">
  18.         Colour: <input type="text" name="Colour"><br>
  19.         Make: <input type="text" name="Make"><br>
  20.         Model: <input type="text" name="Model"><br>
  21.         License Plate: <input type="text" name="licensePlate"><br>
  22.         <input type="submit" value = "Add Record">
  23.     </form>
  24.     <hr>
  25.    
  26.    
  27.    
  28. <?php
  29.     // MySQL database information
  30.     $servername = "mysql.cs.nott.ac.uk";
  31.     $username = "psxrjt";
  32.     $password = "database123";
  33.     $dbname = "psxrjt";
  34.    
  35.     $conn = mysqli_connect($servername, $username, $password, $dbname);
  36.        
  37.     if(mysqli_connect_errno())
  38.     {
  39.       echo "Failed to connect to MySQL:".mysqli_connect_error();
  40.       die();
  41.     }
  42.     else echo "MySQL connection OK";
  43.    
  44.     if ($_POST['Colour']!="" && $_POST['Make']!=""
  45.     && $_POST['Model']!="" && $_POST['licensePlate']!="")
  46.     {
  47.         $sql="INSERT INTO Vehicles(Colour, Make, Model, VehicleID) VALUES
  48.         ('".$_POST['Colour']."','".$_POST['Make']."','".$_POST['Model']."','".$_POST['licensePlate'].");";
  49.         $result = mysqli_query($conn, $sql);
  50.     }
  51.    
  52.        
  53.     if ($_GET['del']!="")
  54.     {
  55.     $sql="DELETE FROM Vehicles WHERE VehicleID=".$_GET['del'].";";
  56.     $result = mysqli_query($conn, $sql);
  57.     }
  58.    
  59.     // construct the SELECT query
  60.     $sql = "SELECT * FROM Vehicles ORDER BY VehicleID;";
  61.     // send query to database
  62.     $result = mysqli_query($conn, $sql);
  63.    
  64.     echo "<br>" .mysqli_num_rows($result)." rows<br>";
  65.    
  66.     while($row = mysqli_fetch_assoc($result))
  67.     {
  68.         echo "<li>";
  69.         echo $row["VehicleID"];
  70.         echo " (Colour: ".$row["Colour"].") ";
  71.         echo " (Make: ".$row["Make"].") ";
  72.         echo " (Model: ".$row["Model"].") ";
  73.         $ID = $row["VehicleID"];
  74.         echo "<a href='?del=$ID'>delete</a>";
  75.         echo "<br>";
  76.     }
  77.            
  78. mysqli_close($conn);
  79.    
  80. ?>
  81.  
  82.    
  83.    </body>
  84.  
  85.    </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top