Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/exercises/ovning9/3/

laggatill.php
skapatabell.php
visa.php
visaB.php
visaC.php
visaD.php
visaE.php

laggatill.php

77 lines UTF-8 Windows (CRLF)
<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title>Namnlöst dokument</title>
</head>

<body>
  <?php
  $message 
null;
  if (
    isset(
$_POST['regnr']) && isset($_POST['color']) && isset($_POST['garage'])  && 
    !empty(
$_POST['regnr']) && !empty($_POST['color']) && !empty($_POST['garage']) 
  ) {
    
$regnr $_POST['regnr'];
    
$color $_POST['color'];
    
$garage $_POST['garage'];
    
$owner $_POST['owner'];

    include(
'../dbconnection.php');
    try {
      
# prepare
      
$sql "INSERT INTO car (regnr, color, garage, owner) 
          VALUES (?, ?, ?, ?)"
;
      
$stmt $dbconn->prepare($sql);
      
$data = array($regnr$color$garage$owner);
      
$stmt->execute($data);

      echo 
"New record created successfully";
    } catch (
PDOException $e) {
      echo 
$sql "<br>" $e->getMessage();
    }

    
$dbconn null;
  } else {
    
$message .= "<br />Du måste fylla i alla fälten!<br /><br />";
  }
  echo 
$message;
  
?>
  <form method="post" action="">
    <table>
      <tr>
        <td>Regrsteringsnummer*:</td>
        <td><input type="text" name="regnr" size=40 maxlength=100>
        </td>
      </tr>
      <tr>
        <td>Färg*:</td>
        <td><input type="text" name="color" size=40 maxlength=100></td>
      </tr>
      <tr>
      <td>Garage*:</td>
        <td><select name="garage" required>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select></td>
      </tr>
      <tr>
      <td>Ägare*:</td>
        <td><select name="owner" required>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select></td>
      </tr>
      <tr>
      <td>* = obligatoriskt</td>
      <td><button type="submit">Lägg till</button></td>
      </tr>
    </table>
  </form>
  <a href="../ovn_sql3.php">Tillbaks till meny</a>
</body>

</html>