javascript - How to avoid a function directing to another page if an entry is incorrect -
i have remove page can remove entry database pre loaded option box. however, redirects 'remove-module-complete.php' page when type in random text. want direct 'remove-module-complete.php' if actual entry database. javascript doesn't seem working.
i have validation entry 'didnt match item' jquery still directs me 'module remove complete' if press submit.
any help?
here php
<?php if (isset($_post['submit'])){ $modulecode = $_post['modulecode']; $modulecodelen = strlen($modulecode); if ($modulecodelen=6){ $sqltwo = "delete modules id = '$modulecode'"; mysql_query($sqltwo); $restwo =& $db->query($sqltwo); if(pear::iserror($res)){ $errorvar = ($res->getmessage()); echo "<script type='text/javascript'>alert('invalid entry, please try again. error code: $errorvar');</script>"; die; } else echo "<script> location.replace('http://project.ac.uk/remove-module-complete.php'); </script>"; } else echo "<script type='text/javascript'>alert('invalid entry, please try again');</script>"; } ?>
seems have errors(commented lines):
if (isset($_post['submit'])) { $modulecode = $_post['modulecode']; $modulecodelen = strlen($modulecode); // '==', not '=' if ($modulecodelen==6) { $sqltwo = "delete modules id = '$modulecode'"; mysql_query($sqltwo); $restwo =& $db->query($sqltwo); // there no $res variable in given part of code // maybe need use $restwo variable here? if (pear::iserror($res)) { $errorvar = ($res->getmessage()); echo "<script type='text/javascript'>alert('invalid entry, please try again. error code: $errorvar');</script>"; die; } else echo "<script> location.replace('http://project.ac.uk/remove-module-complete.php'); </script>"; } else echo "<script type='text/javascript'>alert('invalid entry, please try again');</script>"; }
Comments
Post a Comment