All pastes #514947 Raw Edit

Someone

public text v1 · immutable
#514947 ·published 2007-05-28 00: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) $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";
	print_r($error);
	if (count($error)==0) echo "You successfully added a book";
	else {
		foreach ($error as $x) {
			echo $x."<br />";
		}
	}
}
?>

<html>
 <body>
  <form action="" method="post">
   Title: <input type="text" name="title" size="50" maxlength="100">
   Author: <input type="text" name="author" size="50" maxlength="100">
   Book ID: <input type="text" name="bookid" size="5" maxlength="32">
   <input type="submit" value="Add book">
  </form>
 </body>
</html>