Hi,
I have a web page(admin page) and using some JQuery I have it so that when you click the 'Add News' link a form appears in another div. This bit works ok.
The form data gets sent to another php file which the either adds the data to a mysql table or if the user has left out something in the form it tells them.
The probllem is that if I fill the form out correcttly, it takes me to another page, if I fill it out incorrectly it also takes me to another page telling me what errors I have made.
Is there to get the error displaayed on the same page in the same div, just under the form?
Here are my files so far.
My admin page where i want everthing displayed
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="../css/template.css" rel="stylesheet" type="text/css" />
<link href="../css/adminpanel.css" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#news").click(function(){
$("#container").load("addnewsform.php");
});
});
</script>
<title>Diamondback Tattoo Admin Page</title>
</head>
<body>
<div class="wrap">
<div id="header">
<div id="logo">
<a href="home.php"><img src="../images/siteimages/logo.JPG" alt="Logo image" /></a>
</div>
</div>
<div id="menu">
<div id="content">
<div class="nav">
<div id='cssmenu'>
<ul>
<li><a href='home.php'>Home</a></li>
<li><a href='#' id='1' class="category">Galleries</a> </li>
<li><a href='news.php'>News</a></li>
<li><a href='#' id='3' class="category">Contact</a></li>
<li><a href='#' id='4' class="category">Links</a></li>
<li><a href='#' id='5' class="category">Buy Vouchers</a></li>
</ul>
</div>
<div id='adminmenu'>
<ul>
<li><a href='#' id='news'>Add News Item</a></li>
<li><a href='#' id='1' class="category">Add/Change Contact Details</a> </li>
<li><a href='news.php'>Add Links</a></li>
<li><a href='#' id='3' class="category">Add/Change Homepage Info</a></li>
<li><a href='#' id='4' class="category">Remove News Item</a></li>
<li><a href='#' id='5' class="category">Remove Links</a></li>
</ul>
</div>
</div>
<div style="clear: both;"> </div>
<div id="container">
<span class="text">hi</span>
</div>
<div class="contentimgs">
<img class="tat3" src="../images/siteimages/nikhands.jpg" alt="Tattooed Hands Image" />
</div>
</div>
</div>
<div id="footer">
<p>© Copyright of Diamondback Tattoo<br />Site Developed by Webslinger Development</p>
</div>
</div>
</body>
</html>
My php file to send the form to the admin page.
<?php
// this will be the string that you will return into the container div
$returnHtml = '';
// construct the html to return
$returnHtml .= "<span class='text'>";
$returnHtml .= "Add a news item";
$returnHtml .= "</span>";
$returnHtml .= "<form class='form1' action='newsadd.php' method='post' enctype='multipart/form-data' name='add_news-form' id='add_news_form'>";
$returnHtml .= "<h1 style='margin-bottom: 0px'><span class='text'>Fill in all the details:</span></h1>";
$returnHtml .= "<input type=text name='atitle' /><b><span class='text'>Title<span></b>";
$returnHtml .= "<br />";
$returnHtml .= "<textarea rows='8' name='acontent'></textarea><b><span class='text'>Content</span></b>";
$returnHtml .= "<br />";
$returnHtml .= "<br />";
$returnHtml .= "<input type='submit' name='submit' value='Add News Item' />";
$returnHtml .= "<input type='hidden' value='new' />";
$returnHtml .= "</form>";
// display the html
echo $returnHtml;
?>
And newsadd.php
<?php
include '../inc/connect.php';
// validate form fields
if (!empty($_REQUEST['atitle'])){
$atitle = $_REQUEST['atitle'];
}
else{
$atitle = NULL;
echo "<span class='end'><p>Enter a title for the News Item</p></span>";
}
if (!empty($_REQUEST['acontent'])){
$acontent = $_REQUEST['acontent'];
}
else{
$acontent = NULL;
echo "<span class='end'><p>Enter content for the News Item</p></span>";
}
//if evetrything is ok continue with form post inserting data to table
if ($atitle && $acontent){
if (isset($_POST['submit'])){
$r = mysql_query("INSERT INTO news VALUES ('', now(), '$atitle', '$acontent')");
echo "<span class='end'><p>The news article has been added to the website</p></span>";
}
}
?>
Thanks for looking...................