forum data is not being send to xampp server despite code giving no errors

19 views Asked by At

is my code alright like i checked my code multiple times still didn't see any errors and data is not being send to server side , im even getting message user register successful like i don't understand what could be the problem like its checking in database

my code below

<!DOCTYPE html>
<html lang="en">
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
    <div class=" container">
        <?php 
        var_dump($_POST);
        if(isset($_POST["submit"])){
            $user_name =$_POST["user_name"];
            $email =$_POST["email"];
            $password =$_POST["password"];
            $reapeat_password =$_POST["reapeat_password"];
            $contact =$_POST["contact"];
            $passwordhash = password_hash( $password, PASSWORD_DEFAULT );
            $errors = array();

            if(empty($user_name) OR empty($email) OR empty($password) OR empty($reapeat_password) OR empty($contact)  ){
                array_push($errors,"all fileds are required");
            }
            if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
                array_push($errors,"email is not valid");
            }
            if(strlen($password)<9){
                array_push($errors,"paswword must be 9 chracter long");
            }
            if($password!==$reapeat_password){
                array_push($errors,"password does not match");
            }
            if(strlen($contact)<10){
                array_push($errors,"plase enter a right number");
            }
           
            require_once "../config file/config.php";

            // Check if email already exists
            $sql = "SELECT * FROM users WHERE email = '$email'";
            $result = mysqli_query($conn, $sql);
            $rowcount = mysqli_num_rows($result);
            if ($rowcount > 0) {
                array_push($errors, "Email already exists");
            }
                    
            // Check if contact already exists
            $sql = "SELECT * FROM users WHERE contact = '$contact'";
            $result = mysqli_query($conn, $sql);
            $rowcount = mysqli_num_rows($result);
            if ($rowcount > 0) {
                array_push($errors, "Contact already exists");
            }

            // Check if username already exists
            $sql = "SELECT * FROM users WHERE user_name = '$user_name'";
            $result = mysqli_query($conn, $sql);
            $rowcount = mysqli_num_rows($result);
            if ($rowcount > 0) {
                array_push($errors, "Username already exists");
            }
   

            

            if(count($errors)> 0){
                foreach($errors as $error){
                    echo"<div  class='alert alert-danger' role='alert'>$error</div>";
            }
           }else{
            $sql ="INSERT INTO `users` (user_name,email,password ,contact) VALUES (?,?,?,?)";
            $stmt =mysqli_stmt_init($conn);
            $preparestmt = mysqli_stmt_prepare($stmt,$sql);
            if ($preparestmt){
                mysqli_stmt_bind_param($stmt,"ssss", $user_name,$email,$passwordhash,$contact);
                mysqli_stmt_execute($stmt);
                echo " <div  class='alert alert-danger' role='alert'> you are registered successfully </div>";
            } else{
                die("something went wrong");
            }
              
           }
        }

        ?>
        <form action="reister.php" method="post">
            <div class="form-group">
                <input type="text" class="form-control" name="user name" placeholder="user name">
            </div>

            <div class="form-group">
                <input type="text" class="form-control" name="email" placeholder="email">
            </div>

            <div class="form-group">
                <input type="text" class="form-control" name="password" placeholder="password">
            </div>

            <div class="form-group">
                <input type="text" class="form-control" name="reapeat_password" placeholder=" confirm password">
            </div>

            <div class="form-group">
                <input type="text" class="form-control" name="contact" placeholder="contact">
            </div>

            <div class="form-btn">
                <input type="submit" class="btn btn-primary" value="register"name="submit">
            </div>
        </form>
         <div><p>already  registered<a href="login.php">signin</a></p></div>
    </div>
</body>
</html>
my var dump data
Array ( [user_name] => lplpqw [email] => [email protected] [password] => 123456789098765432 [reapeat_password] => 123456789098765432 [contact] => 123456789098765432 [submit] => register ) database connection successful

i try looking var dump and print_r too see my data and console logs didn't see anything like all my values are strings and everything what im thinking could it xampp issue like it happened to me before too with edit data it randomly stooped working then it was working,but i don't know reasons why it happened

0

There are 0 answers