PHP - MySQL - Sign Up Trouble [blank data]

77 views Asked by At


I've a website since 2013. I've signed up quite 12k users. From 5 months I have noticed some blank users. They receive a user-code but "name" "surname" and "email" fields are blanks.
This event happen every 50/100 users registrations. Why? I have tried everything, but in all test I can't sign up without data. Also other people that have made tests can't sign up without insert data. This is the form:

<form action="script/****.php" method="post" onsubmit="return validate()">
<label for="name">Name</label>
<input type="text" id="name" name="name" <?php if($_REQUEST['name'] != "") echo "value='".$_REQUEST['name']."'"; ?> />

<label for="surname">Surname</label>
<input type="text" id="surname" name="surname" <?php if($_REQUEST['surname'] != "") echo "value='".$_REQUEST['surname']."'"; ?> />

<label for="email">Email</label>
<input type="email" id="email" name="email" <?php if($_REQUEST['email'] != "") echo "value='".$_REQUEST['email']."'"; ?> />

<label for="c_email">Retype Email</label>
<input type="email" id="c_email" name="c_email" />

<label for="password">Password</label>
<input type="password" id="password" name="password" />

<label for="c_password">Retype Password</label>
<input type="password" id="c_password" name="c_password" />

<input type="submit" value="registrati" />
</form>

This is the code that stores data on db:

<?php
    function mt_rand_str ($length, $available = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz0123456789') {
        for ($string = '', $i = 0; $i < $length; ++$i) {
            $string .= $available[mt_rand(0, strlen($available)-1)];
        }
        return $string;
    }

    include('connection.php');
    $con = connection();
    $name = $_POST['name'];
    $surname = $_POST['surname'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $bonus = 10;
    $today = new DateTime();
    $signUpDate = $today->format('Y-m-d');

    if(strpos($name,'  ') !== false) {
        echo "
        <script>
        alert('Nome non valido!');
        window.location.href = '../signup.php';
        </script>";
        exit;
    }
    if(strpos($surname,'  ') !== false) {
        echo "
        <script>
        alert('Cognome non valido!');
        window.location.href = '../signup.php';
        </script>";
        exit;
    }
    if(strpos($email,' ') !== false) {
        echo "
        <script>
        alert('Email non valida!');
        window.location.href = '../signup.php';
        </script>";
        exit;
    }
    if(strpos($password,' ') !== false) {
        echo "
        <script>
        alert('Password non valida!');
        window.location.href = '../signup.php';
        </script>";
        exit;
    }

    connectionCheck($con);
    userDbCheck($con);

    $checkEmail = mysqli_query($con,"Select * from Users_DB where email = '$email'");
    if(!mysqli_fetch_assoc($checkEmail)) {
        do {
            $userCode = mt_rand_str(8);
        }
        while(mysqli_fetch_assoc(mysqli_query($con,"select * from Users_DB where binary UserCode = '$userCode'")));

        $value = 20;

        mysqli_query($con,"Insert into User_DB (UserCode,Name,Surname,Phone,Email,Password,SignUpDate,bonus)
                                values ('$userCode','$name','$surname','','$email','$password','$signUpDate','$bonus')");
    }
    else {
        echo "
        <script>
            alert('Email exists already!');
            window.location.href = '../signup.php';
        </script>";
    }
?>

I hope you can find what I have not. As you can see, I've put in php code some data check too.
So I have
1) HTML5 check: type="email". I'm thinking to put also "pattern match" in all fields
2) JavaScript check
3) PHP check
I'm so desperate...
Thank you before.

0

There are 0 answers