SHARE
TWEET

Untitled

a guest Dec 13th, 2016 95 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.    <h1> Add Vehicle</h1>
  11.    
  12.     <form method="POST">
  13.         Colour: <input type="text" name="Colour"><br>
  14.         Make: <input type="text" name="Make"><br>
  15.         Model: <input type="text" name="Model"><br>
  16.         License Plate: <input type="text" name="licensePlate"><br>
  17.         <input type="submit" value = "Add Record">
  18.     </form>
  19.     <hr>
  20.    
  21. <?php
  22.     // MySQL database information
  23.     $servername = "####";
  24.     $username = "####";
  25.     $password = "####";
  26.     $dbname = "#####";
  27.    
  28.     $conn = mysqli_connect($servername, $username, $password, $dbname);
  29.        
  30.     if(mysqli_connect_errno())
  31.     {
  32.       echo "Failed to connect to MySQL:".mysqli_connect_error();
  33.       die();
  34.     }
  35.     else echo "MySQL connection OK";
  36.    
  37.        
  38.     if ($_POST['colour']!="" && $_POST['make']!=""
  39.     && $_POST['model']!="" && $_POST['vehicleID']!="")
  40.     {
  41.         $sql="INSERT INTO Vehicles(Colour, Make, Model, VehicleID) VALUES
  42.         ('".$_POST['Colour']."','".$_POST['Make']."','".$_POST['Model']."','".$_POST['licensePlate'].");";
  43.         $result = mysqli_query($conn, $sql);
  44.     }
  45.    
  46.        
  47.     if ($_GET['del']!="")
  48.     {
  49.     $sql="DELETE FROM People WHERE VehicleID=".$_GET['del'].";";
  50.     $result = mysqli_query($conn, $sql);
  51.     }
  52.    
  53.     // construct the SELECT query
  54.     $sql = "SELECT * FROM Vehicles ORDER BY VehicleID;";
  55.     // send query to database
  56.     $result = mysqli_query($conn, $sql);
  57.    
  58.     echo "<br>" .mysqli_num_rows($result)." rows<br>";
  59.    
  60.     while($row = mysqli_fetch_assoc($result))
  61.     {
  62.         echo "<li>";
  63.         echo $row["VehicleID"];
  64.         echo " (Colour: ".$row["Colour"].") ";
  65.         echo " (Make: ".$row["Make"].") ";
  66.         echo " (Model: ".$row["Model"].") ";
  67.         $ID = $row["VehicleID"];
  68.         echo "<a href='?del=$ID'>delete</a>";
  69.         echo "<br>";
  70.     }
  71.            
  72. mysqli_close($conn);
  73.    
  74. ?>
  75.  
  76.    
  77.    </body>
  78.  
  79.    </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