0

I have created a register page and code that connects to a database. The code so far works and adds new people to the database, However an error is thrown after the user has been added.

Thanks.

This is the error:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\index.php on line 22

<?php
include("config.php");
if(isset($_POST['submit'])) {
$email = $_POST['Email'];
$username = $_POST['Username'];
$firstname = $_POST['Firstname'];
$secondname = $_POST['Secondname'];
$password = ($_POST['Password']);
$confPassword = ($_POST['conpassword']);
$number = ($_POST['num']);
if(isset($email,$username,$password,$confPassword)){
    if(strstr($email,"@")){

        if($password == $confPassword){

            $query = $dbc->prepare("SELECT * FROM users WHERE userUsername = ? OR userEmail = ?");
            $query = $query->execute(array(
                    $username,
                    $email
                ));

                $count = mysql_num_rows($query);

                if($count == 0){
                    $query = $dbc->prepare("INSERT INTO users SET userUsername = ?, userEmail = ?, userPassword = ?, userFirstName = ?, userSecondName = ?, userPhone = ? ");
                    $query = $query->execute(array(
                        $username,
                        $email,
                        $password,
                        $firstname,
                        $secondname,
                        $number
                        ));
                }
                        if($query){
                            echo ("You Account Has Been Registered, You May Now Login");
                        }
                }else{
                    echo("User Already Has That Username");
                }


        }else{
            echo("Your Passwords Do Not Match");
        }
    }else{
        echo ("Invalid Email");
    }
}
?>



<html>



<head>
    <title>Aaron Nebbs</title>
    <link rel="stylesheet" type="text/css" href="Styles/style.css">


</head>

<body>
    <div class="container">

            <form action="index.php" method="POST">
            <table>
                <tr>
                    <td>First Name:</td>
                    <td><input type="text" name= "Firstname"></td>
                </tr>

                <tr>
                    <td>Surname:</td>
                    <td><input type="text" name= "Secondname"></td>
                </tr>



                <tr>
                    <td>Username:</td>
                    <td><input type="text" name= "Username"></td>
                </tr>
                <tr>
                    <td>Email:</td>
                    <td><input type="text" name= "Email"></td>
                </tr>

                <tr>
                    <td>Phone Number:</td>
                    <td><input type="text" name= "num"></td>
                </tr>

                <tr>
                    <td>Password:</td>
                    <td><input type="password" name= "Password"></td>
                </tr>

                <tr>
                    <td>Confirm Password:</td>
                    <td><input type="password" name="conpassword"></td>
                </tr>
            </table>

            <input type="submit" name="submit" value="Register">
        </form>

    </div>






<script src="Scripts/jQuery.js"></script>
<script src="Scripts/js.js"></script>
</body>

</html>
Dharman
  • 26,923
  • 21
  • 73
  • 125
Aaron Nebbs
  • 394
  • 1
  • 5
  • 13

0 Answers0