<script type="text/javascript"> $(document).ready(function() { $('#submit').click(function() { var title = $('#title').val(); var body = $('#body').val(); if(title.length<5) { $('#er').html('Error mesg'); return false; } if(body.length<500) { $('#er').html('error msg'); return false; } }); }); </script>
<?php error_reporting('E_ALL ^ E_NOTICE'); if(isset($_POST['submit'])) { $title=$_POST['title']; $body=$_POST['body']; if (strlen($title) < 5) { $er = "Title must be of minimum 5 characters"; } else if (strlen($body) <500 ) { $er = "Body must be of minimum 500 characters"; } else { // pdo statement to insert data in db if ($statement->rowCount() == 1) { $er = "Congratulations, successfully posted."; } else { print_r($db->errorInfo()); } } } ?>
<div id="er"><?php echo $er; ?></div>
<?php if(!empty($er)) { echo '<div id="er">'.$er.'</div>'; } ?>
<div id="er" style="display:none" />.when error occurs call $("#er").show();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)