0

I have a sign-up link which when clicked a sign-up div pops up and after successful registration a javascript alert is produced saying "Registration Successful".. The problem is that when I click on ok the page reloads and then when I click on sign-up the height of the sign-up pop up div is automatically increased to the bottom of the page...

Signup pop-up div before javascript alert Signup pop-up div before javascript alert

Signup pop-up div after registration and after clicking ok of javascript alert Signup pop-up div after registration and after clicking ok of javascript alert

The login and sign-up page is in index.php...

config.php

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "shop";
try {
    $db = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (Exception $ex) {
    echo "Error: ".$ex->getMessage();
    die();
}

The php script for registration

<?php
session_start();
include 'config/config.php';
if(isset($_POST['register'])){
    $name=$_POST['name'];
    $email=$_POST['email'];
    $mobile=$_POST['mobile'];
    $password=$_POST['password'];
    $query = $db->prepare("SELECT email FROM user_info WHERE email= ?");
    $query->execute(array($email));
    if($query->rowCount()>0){
        echo '<script type="text/javascript">alert("Sorry Email already exist");</script>';
    }
    else{
    $query = $db->prepare("SELECT mobile FROM user_info WHERE mobile= ?");
    $query->execute(array($mobile));
    if($query->rowCount()>0){
        echo '<script type="text/javascript">alert("Sorry Phone Number already exist");</script>';
    }
    }
    $query = $db->prepare("INSERT INTO user_info(name, email, mobile, password) VALUES(?, ?, ?, ?)");
    $query->execute(array($name, $email, $mobile, $password));
    echo '<script type="text/javascript">alert("Registration Successful");</script>';
}
?>

The html form

<div id="small-dialog2" class="mfp-hide agileinfo">
                        <div class="pop_up">
                                                    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
                                <h3>SIGN UP</h3>
                                <input type="text" name="name" placeholder="Name" required="">
                                                                <input type="email" name="email" placeholder="Email" title="Please feed in a correct email id" required="">
                                                                <input type="number" name="mobile" placeholder="Phone Number" pattern="[789][0-9]{9}" title="Your mobile number must have atmost 10 digits." required="">
                                                                <input type="password" Name="password" placeholder="Password" pattern=".{6,20}" title="Your password must have a length between 6 to 20 charecters." required="">
                                <div class="send-button wthree agileits">
                                                                    <input type="submit" name="register" value="SIGN UP">
                                </div>
                            </form>

                        </div>
                    </div> 

The css for popup

div#small-dialog1, div#small-dialog2, div#small-dialog3, div#small-dialog4 {
            padding: 30px;
            width: 20%;
            height: 100%;
            margin: 0 auto;
            background: #F5F5F5;
        }
  • 2
    can you reduce your question to the minimum, verifyable example? – Jeff Jun 16 '17 at 15:39
  • Try to create a clear environment, where are only the required components are. Check, is it works? If yes, step by step broaden with other parts. You will catch where is the error. – vaso123 Jun 16 '17 at 15:42
  • The problem shouldn't be on the PHP side as this is a client side issue. One question here, do you want the pop-up to show up after successful registration? If no, then maybe you can set a cookie after the JavaScript alert function within the PHP code. Upon loading the page, check if that cookie is set (or true), then decide if the pop-up should appear or not. – jacktheking Jun 16 '17 at 15:54
  • **Never store plain text passwords!** Please use ***PHP's [built-in functions](http://jayblanchard.net/proper_password_hashing_with_PHP.html)*** to handle password security. If you're using a PHP version less than 5.5 you can use the `password_hash()` [compatibility pack](https://github.com/ircmaxell/password_compat). ***It is not necessary to [escape passwords](http://stackoverflow.com/q/36628418/1011527)*** or use any other cleansing mechanism on them before hashing. Doing so *changes* the password and causes unnecessary additional coding. – Jay Blanchard Jun 16 '17 at 15:57

0 Answers0