Example #1
0
<?php

require 'init_form.php';
session_start();
if (formIsBeingSubmitted()) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $db = new Database();
    $db->query("INSERT INTO users (username, password) VALUES (\"{$username}\", \"{$password}\")");
    $_SESSION['user'] = $username;
    $_SESSION['user_id'] = $db->getLastInsertedId();
    header("Location: http://rdripley.com/forum");
}
?>

<html>
	<head>
		<title>
			register
		</title>
	</head>

	<body>

		<form method="POST">
			<label>
				Username
				<input type="text" name="username">
			</label>

			<br>
Example #2
0
<?php

require 'init_form.php';
session_start();
if ($_SESSION['user'] === NULL) {
    header("Location: http://rdripley.com/forum");
}
if (formIsBeingSubmitted()) {
    $title = $_POST['title'];
    $content = $_POST['content'];
    $authorId = $_SESSION['user_id'];
    $date = new DateTime();
    $date = $date->format('Y-m-d H:i:s');
    $db = new Database();
    $db->query("INSERT INTO threads (title, author_id) VALUES (\"{$title}\", \"{$authorId}\")");
    $threadId = $db->getLastInsertedId();
    $db->query("INSERT INTO posts (author_id, content, thread_id, date) VALUES (\"{$authorId}\", \"{$content}\", \"{$threadId}\" ,\"{$date}\")");
    header("Location: http://rdripley.com/forum");
}
?>

<?php 
require 'header.php';
?>

<h3>Create a New Thread</h3>

<hr>

<form action="make_thread.php" method="post">
	<p>