-4

But i am facing this error

Fatal error: Uncaught TypeError: mysqli_query(): Argument #1 ($mysql) must be of type mysqli, bool given in F:\Xampp\htdocs\User-Registration-System\index.php:20 Stack trace: #0 F:\Xampp\htdocs\User-Registration-System\index.php(20): mysqli_query(false, 'SELECT * FROM `...') #1 {main} thrown in F:\Xampp\htdocs\User-Registration-System\index.php on line 20

<?php include 'connection.php';

if (isset($_REQUEST['register'])) {
    $username = $_POST['username'];
    $email = $_POST['email'];
    $mobile = $_POST['mobile'];
    $password = md5($_POST['password']);
    $cpassword = md5($_POST['cpassword']);

    if (
        empty($_POST['username']) ||
        empty($_POST['email']) ||
        empty($_POST['mobile']) ||
        empty($_POST['password']) ||
        empty($_POST['cpassword'])
    ) {
        echo 'Please fill all required fields!';
    } else {
        $usernameQuery = "SELECT * FROM `register` WHERE `username`='$username'";
        $uq = mysqli_query($conn, $usernameQuery);
        $emailQuery = "SELECT * FROM `register` WHERE `email`='$email'";
        $eq = mysqli_query($conn, $emailQuery);
        $mobileQuery = "SELECT * FROM `register` WHERE `mobile`=$mobile";
        $pq = mysqli_query($conn, $mobileQuery);
        if (mysqli_num_rows($uq > 0)) {
            echo "username already exist";
        } elseif (mysqli_num_rows($eq > 0)) {
            echo "username already exist";
        } elseif (mysqli_num_rows($pq > 0)) {
            echo "someone already register with this phone number";
        } elseif ($password === $cpassword) {
            $iquery = "INSERT INTO `register`(`username`,`eamil`,`mobile`,`password`) VALUES('$username','$email','$mobile','$password')";
            mysqli_query($conn, $iquery);
        } else (header('location:index.php'));
    }
}

?>
<!DOCTYPE html>
<html>

<head>
    <title>Page Title</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
</head>

<body>

    <div class="container">
        <div class="h1">Register Here</div>
        <form action="" method="post">
            <div class="form-group">
                <label for="exampleInputEmail1">Username</label>
                <input type="text" class="form-control" name="username" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
            </div>
            <div class="form-group">
                <label for="exampleInputEmail1">Email</label>
                <input type="email" class="form-control" name="email" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
            </div>
            <div class="form-group">
                <label for="exampleInputEmail1">Mobile</label>
                <input type="text" class="form-control" name="mobile" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">Password</label>
                <input type="password" class="form-control" name="password" id="exampleInputPassword1" placeholder="Password">
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">Confirm Password</label>
                <input type="password" class="form-control" name="cpassword" id="exampleInputPassword1" placeholder="Password">
            </div>
            <br>
            <button type="submit" name="register" class="btn btn-primary">Submit</button>
        </form>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
</body>

</html>
brombeer
  • 8,716
  • 5
  • 21
  • 27
Ahtesham
  • 1
  • 4
  • 4
    Does this answer your question? [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – El_Vanja Mar 24 '21 at 10:04
  • 3
    Being a newbie excuses you from doing any work? Read the linked question, find out the actual error. We can't debug your database connection for you. – El_Vanja Mar 24 '21 at 10:07
  • actually i dont understand what is this error can you explain in simple langauge what error saying i think my code is good but idk what this error saying – Ahtesham Mar 24 '21 at 10:15
  • Look, it seems as though your connection failed. To get a *clearer error*, please follow the instructions from the linked question. Once you share some proper details, we can identify the problem (if you can't do it yourself). But we can't fix it like this, because we don't know what's happening. – El_Vanja Mar 24 '21 at 10:36

1 Answers1

0

I solve this problem , actually i was using > in under function that is a mistake.

if (mysqli_num_rows($uq) > 0)){}
Ahtesham
  • 1
  • 4
  • That can't be the problem. The error literally points to a completely different line with a different kind of error. But if it solved your problems, then I guess everything is... fine... – Chryfi Mar 24 '21 at 13:38