Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/projekt/quiz/
createtable.php
dbconnection.php
deletepost.php
deletetable.php
insertdefaultposts.php
insertposts.php
leaderboard.php
log_in.php
log_out.php
main.php
question_maker.php
quiz_form.php
quiz_list.php
quiz_maker.php
result.php
selectposts.php
sign_in.php
style.js
updateposts.php
insertposts.php
59 lines UTF-8 Windows (CRLF)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
<!-- insertpost.php -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Namnlöst dokument</title>
</head>
<body>
<?php
$message = null;
if (isset($_POST['username']) && isset($_POST['password']) &&
!empty($_POST['username']) && !empty($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
include ('dbconnection.php');
try {
# prepare
$sql = "INSERT INTO quiz_users (username, password, reg_date)
VALUES (?, ?, now())";
$stmt = $dbconn->prepare($sql);
# the data we want to insert
$data = array($username, $password);
# execute width array-parameter
$stmt->execute($data);
echo "New record created successfully";
$lastId = $dbconn->lastInsertId();
echo "id på sista posten: $lastId";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$dbconn = null;
} else {
$message .= "<br />Du måste fylla i förnamn och efternamn!<br /><br />";
}
echo $message;
?>
<form method="post" action="">
<table>
<tr>
<td>Förnamn*:</td>
<td><input type="text" name="username" size=40 maxlength=100>
</td>
</tr>
<tr>
<td>Efternamn*:</td>
<td><input type="text" name="password" size=40 maxlength=100></td></tr>
<tr>
<td>* = obligatoriskt</td>
<td><button type="submit">Lägg till</button></td></tr>
</table>
</form>
</body>
</html>