All pastes #514781 Raw Edit

Stuff

public text v1 · immutable
#514781 ·published 2007-05-27 22:13 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']==null || $_POST['author']==null || $_POST['bookid']==null) $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";
	}
}

if (isset($error) && count($error)!=0 && isset($_POST)) {
	foreach ($error as $x) {
		echo $x."<br />";
	}
}
?>

<html>
	<h1>Add books</h1>
	<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>
</div></div>
</html>