Webbserv1: Källkod
Webbserverprogrammering 1

Show sourcecode

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

webbsrvprg/projects/quiz/

quiz.php
quiz_create.php
quiz_created.php
quiz_home.php
quiz_login.php
quiz_results.php
quiz_signup.php

quiz_signup.php

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

<body>
<?php
include ('../../dbconnection.php');
$message null;
  if (isset(
$_POST['user']) && isset($_POST['pass']) && 
  !empty(
$_POST['user']) && !empty($_POST['pass'])) {
    
$user $_POST['user'];
    
$pass $_POST['pass'];
    
    try {    
        
$sql "INSERT INTO quizusers (user, pass, type, time) 
          VALUES (?, ?, ?, now())"
;
        
$stmt $dbconn->prepare($sql);
        
$data = array($user$pass"no");
        
$stmt->execute($data);
            
        echo 
"Konto skapat";
        
$lastId $dbconn->lastInsertId();
    }
    catch(
PDOException $e)  {
        echo 
$sql "<br>" $e->getMessage();
    }
    
    
$dbconn null;
  } else {
    
$message .= "<br />Du måste fylla i fälten!<br /><br />";
  }
echo 
$message;
?>
<form method="post" action=""> 

  Användarnamn: 
  <input type="text" name="user" size=40 maxlength=100 required><br><br>

  Lösenord: 
  <input type="text" name="pass" size=40 maxlength=100 required><br><br>

  <button type="submit">Skapa konto</button><br><br>

  <a href="quiz_login.php">Till inloggningssida</a>
</form>
</body>
</html>