Display Errors or Success message on same self-referring form

Hello chaps,

I have a basic form that takes in details about a book and places them into an database.

All the validation is done in PHP (omitted here for clarity) and any errors that validation throws up and passed into an array, which then displays the errors to the users (if any). However, when the form is submitted, the errors/success message displays on a new page and you have to click the BACK button in order to see the form again. Is there a way to display these error/success messages under the submit button (or simply on the same page) so the user doesn’t have to click back and forth?

Thanks for you time and if you need anything clarifying, please ask.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
  <head>
    <title>The Bookshop | Add Book</title>
    <link href="styles.css" rel="stylesheet" type="text/css" />
	
<meta http-equiv="content-type"
        content="text/html; charset=utf-8" />
	</head>
<body>

				<?php
					$db=sqlite_open("/Bookshop.db", 0666, $error);

					if (!$db)
					{
					  die($error);
					}
				?>
				
				<?php
					
					if($_SERVER['REQUEST_METHOD'] == 'GET')
					{
				?>
				
				
<div id="wrapper">
	<div id="header">
		<h1>&nbsp;</h1>
	
		<div id="search">
		<form id="searchResults" action="searchResults.php" method="post">
		
			<input id="userInput" name="userInput" size="30" maxlength="205" value="" type="text"/>
			<input name="searchButton" class="searchButton"  value="Search" type="submit"/>
			<select name="bookCategory" id="selectCategory">
				<?php
				
					//ToDo: Display categories
					
				?>
			</select>
			<input name="searchCategoryButton" class="searchButton"  value="Go" type="submit"/>
			
			</form>
			</div>
		
		
		</div><!--header-->
	
			<div id="content">
				<h2>Add Book</h2>
	
					<div id="contactform">
						<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') ?>"  method="post" class="contact" id="addBook" enctype="multipart/form-data">
							<fieldset>
								<legend>Add Book</legend>
								
								<div>
									<label for="bookTitle" class="fixedwidth">Book Title*</label>
									<input type="text" class="boxWidth" name="bookTitle" id="bookTitle"/><em class="helpPrompt">Less than 100 characters</em>
								</div>
								<div>
									<label for="bookAuthor" class="fixedwidth">Book Author*</label>
									<input type="text" class="boxWidth" name="bookAuthor" id="bookAuthor"/><em class="helpPrompt">Less than 100 characters</em>
								</div>
								<!--<div>
									<label for="bookISBN" class="fixedwidth">Book ISBN*</label>
									<input type="text" class="boxWidth" name="bookISBN" id="bookISBN"  /><em class="helpPrompt">10 digit number</em>
								</div>-->
								<div>
									<label for="bookPrice" class="fixedwidth">Book Price*</label>
									<input type="text" class="boxWidth" name="bookPrice" id="bookPrice"/><em class="helpPrompt">Number greater than 0</em>
								</div>
								<!--<div>
									<label for="bookFileName" class="fixedwidth">Book File Name*</label>
									<input type="text" class="boxWidth" name="bookFileName" id="bookFileName"/><em class="helpPrompt">10 digit number followed by .jpeg or .jpg or .gif</em>
								</div>-->
									

								<div>
								<label for="bookCategory" class="fixedwidth">Book Category*</label>
									<select name="bookCategory" id="bookCategory">
										<?php
										
											//ToDo: add categories
										?>
									</select>
								</div>
								<div>
									<label for="file" class="fixedwidth">Book Image*</label>
									<input type="file" name="bookImage" id="bookImage" /><em class="helpPrompt">.jpg, .jpeg or .gif 100KB or less</em>
								</div>
								
									
								<br />
								<br />
								<div>
									<p><em>*denotes a mandatory field</em></p>
								</div>
								
								<div class="buttonarea">
									<input type="submit" value="Enter Book" name="submit"  />
								</div>
								<br />
								
								<div><!-- form reset -->
									<input type="button" id="clearForm" value="Clear Form" onClick="this.form.reset()" />
								</div>
								
								<div id="testing"></div>
								
							</fieldset>
						</form>
					</div> <!-- contactform-->
			</div><!--content-->
			<div id="footer">
					<p>&copy; The Bookshop 2012 | <a href="/searchBook.php">Home</a> | <a href="/addBook.php">Add a new book</a> | <a href="/dbInit.php">Re/initialise the database</a></p>
			</div> <!--footer-->	
			
			
	</div><!--wrapper-->


								
								
								<?php
								}
									elseif ($_SERVER['REQUEST_METHOD'] == 'POST')
								{

                                                                                $errors = array();
									
										//Validation removed for clarity

                                                                               //ANY ERRORS ARE PLACED INTO AN ARRAY

					                                        if(count($errors) == 0)
										{
											
											$title = 	sqlite_escape_string($_POST['bookTitle']);
											$author = 	sqlite_escape_string($_POST['bookAuthor']);
											$price 	= 	sqlite_escape_string($_POST['bookPrice']);
		                                                                        $isbn = sqlite_escape_string($_POST['bookISBN']);
											
											
											
											sqlite_query($db, "INSERT INTO Books VALUES ('$title', '$author', '$isbn', '$price')");
										?>	
											<p id="success"> Book added successfully. Please use the browser's back button to add another book.</p>
										
										<?php										
										}
										else
										{
										?>
											<p> Please check the following details: </p>
											
											<ol>
											<?php
											foreach ($errors as $error)
											{
												echo '<li class="error">' . $error . '</li>' . "\
";
											}
											?>
											<ol>
											
											<p><strong>Please push the back button to fix these errors</strong></p>
											
										<?php
										}
								}
								else
								{
									die("problem: this script uses neither POST or GET requests");
								}											
							?>
								
			
  </body>
 </html>