php - Javascript Alert Window Redirects to Another Webpage -
<?php session_start(); include_once "connect.php"; $fullname = $_post['fullname']; $username = $_post['username']; $emailadd = $_post['email']; $password = $_post['password']; $query = mysql_query("select * users username = '$username' "); $result = mysql_fetch_array($query); if($fullname == "") { ?> <script> alert("full name required!"); window.location.href = "registeruser.php"; </script> <?php } else { if ($username == "") { ?> <script> alert("invalid username!"); window.location.href = "registeruser.php"; </script> <?php } else { if($username == $result['username']) { ?> <script> alert("username exists!"); window.location.href = "registeruser.php"; </script> <?php } else { if ($emailadd == $result['email']) { ?> <script> alert("email address required!"); window.location.href = "registeruser.php"; </script> <?php } else { if ($password == "") { ?> <script> alert("username required!"); window.location.href = "registeruser.php"; </script> <?php } else { if($_post['password']==$_post['confirmpass']) { mysql_query("insert users (fullname, username, email, password) values ('$fullname', '$username', '$emailadd', '$password')" ); mysql_close(); ?> <script> alert("registered successfully!"); window.location.href = "index.php"; </script> <?php } else { ?> <script> alert("password , confirm password not match"); window.location.href = "registeruser.php"; </script> <?php } } } } } } ?>
it works fine. problem is: the alert window shows web page , not within webpage okay looks awful direct user web page without having contents there. if me please on how fix , make javascript alert window display on same web page only. actually, have tried solutions this..
if($fullname == "") { echo '<script>'; echo 'alert("full name required!")'; echo 'window.location.href = "registeruser.php"'; echo '</script>'; }
use base url , paste custom path page like:
<?php if($fullname == "") { ?> <script> var mybaseurl = <?php echo base_url_constant?> var customurl = mybaseurl."/registeruser.php"; alert("full name required!"); window.location.href = customurl; </script> <?php } ?>
and should avoid echoing script, use regular script block enclosing php tags.
Comments
Post a Comment