I am having a problem on notifying the user when he/she submit a empty form. When I submit an empty form, the system doesn't notify or alert the user that the form is empty. And when I put a title and I leave the content textbox empty its still add to the database and notify that it successfully added. Same goes when I leave the title textbox empty. The two textboxes should have contain texts before submitting. Here is my code...
<?php
extract($_POST);
if($submit=='submit' || strlen($service_name)>0 )
{
$rs=mysql_query("select * from tblservices where service_name='$service_name'");
if (mysql_num_rows($rs)>0)
{
echo '<div class="n_error"><p>Opps! Service Already Exist.</p></div>';
echo '<button type="submit" href="add_service.php">Try again.</button>';
exit;
}
mysql_query("insert into tblservices(service_name, service_content) values ('$service_name', '$service_content')") or die(mysql_error());
echo '<div class="n_ok"><p>Success! Service has been added.</p></div>';
$submit="";
}
?>
<form method="post">
<div class="element">
<label for="service_name">Service Title <span class="red">(required)</span></label>
<input name="service_name" id="service_name" type="text" class="text err" />
</div>
<div class="element">
<label for="content">Page content <span class="red">(required)</span></label>
<textarea name="service_content" id="service_content" class="textarea" rows="10"></textarea>
</div>
<div class="entry">
<button type="submit">Preview</button> <button type="submit" class="add">Save page</button> <button class="cancel">Cancel</button>
</div>
</form>
Please, help me. Advance Happy new year.. :D