SHARE
TWEET

Untitled

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