All pastes #510350 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-05-25 21:21 UTC
rendered paste body
<?php
session_start();
// Coded by Starholdest/Elliott Gervais Copyright © 2006-2007
require("../sources/connect.php");
require("../sources/login.php");

if ($_POST) {
	$_POST	= array_map('mysql_real_escape_string', $_POST);
	$error	= array();
	$query = mysql_fetch_array(mysql_query("SELECT * FROM `books` WHERE `title`='".($_POST['title'])."' AND `author`='".$_POST['author']."'")) or die(mysql_error());
  
  if ($query >= 1) $error[]="That book already exists!";
	if($_POST['title'] && $_POST['author'] && $_POST['bookid']) $error[]="Please fill in the whole form";
	if(is_numeric($_POST['bookid'])) $error[]="Book ID needs to be a number";
	
	if (count($error)==0) {
		echo "You successfully added a book";
	}
}
?>
<html>
	<h1>Add books</h1>
<?php
if (count($error)!=0 && $_POST) {
	echo "<div><h1>ERRORS</h1>";
	foreach ($error as $x) {
		echo $x."<br />";
	}
	echo "</div>";
}
?>
	<form method="POST" action="">
	Title: <input type="text" name="title" size="50" maxlength="100"><br/>
	Author: <input type="text" name="author" size="50" maxlength="100"><br/>
	Book ID: <input type="text" name="bookid" size="5" maxlength="32"><br/><br/>
	<input type="submit" value="Add book"></form>
	<br/><br/><a href="./adminmain.php">Back to the Admin Control Panel</a><br/><a href="./adminbooks.php">View booklist / delete books</a>
</html>