PHP registration from not working - mysqli->query

95 Views Asked by At
 <?php

include('connect.php');


    if (isset($_POST['username']) && isset($_POST['password'])){

        $username = $_POST['username'];

        $email = $_POST['email'];

        $password = $_POST['password'];

        global $mysqli;

        $query = ("INSERT INTO lr (username, password, email) VALUES ('$username', '$password', '$email')");

        $result = $mysqli->query($query, $connection) or die(mysql_erorr());

        if($result === true){

            $msg = "User Created Successfully.";

        }

    }


  ?>

Html:

<form id="RegisterUserForm" action="" method="post" enctype="multipart/form-data">
    <fieldset>
         <p>
            <label for="name">Name</label>
            <input id="name" name="name" type="text" class="text" value="" />
         </p>

         <p>
            <label for="tel">Email</label>
            <input id="email" name="email" type="email"  value="" />
         </p>
         <p>
            <label for="Username">Username</label>
            <input id="username" name="username" type="username"  value="" />
         </p>
         <p>
            <label for="email">Password</label>
            <input id="password" type="password" name="password"  class="text" value="" />
         </p>

         <p>
            <label for="Cpassword">Confirm Password</label>
            <input id="Cpassword" name="Cpassword" class="text" type="password" />
         </p>

         <p>
            <label for="acceptTerms">
                I agree to the <a href="">Terms and Conditions</a> and <a href="">Privacy Policy</a><br/>
                <input id="acceptTerms" name="acceptTerms" type="checkbox" />
            </label>
         </p>

        <p>

                    Upload a picture of your student ID. This is for your own safety from fraud attempts


    <input type="file" name="fileToUpload" id="fileToUpload" style="color:green">
     <input type="submit" value="Upload Image" name="submit" style="color:green">
     <br/><br/><br/> 
        </p>

          <input type="submit" id="registerNew" value="Register" />

    </fieldset>


  ad

 </form> 

THIS IS MY CODE, WHEN I CLICK ON THE REGISTER BUTTON IT GIVES ME THIS ERROR

" Fatal error: Call to a member function query() on a non-object in C:\wamp\www\Unnamed Site 2\Signup.php on line 112"

i AM STILL A NEW TO THIS PHP STUFF NEED HELP PLEASE!!!

ASLO WHEN I TRY TO CONNECT MY DATBASE THRU DREAMWEAVER IT GIVES ME AN ERROY SAYING THAT THERE IS NO DTATABASES ABAILABE

THANKS IN ADVANCE

1

There are 1 best solutions below

0
On

Call to a member function query() means that you are trying to use a function called query, that does not exist as a php or user defined function.

Your variable $query should not have ( ) around it. That is used to call a function.

Just only use $query = "your sql query";

$query = "INSERT INTO lr (username, password, email) VALUES ('$username', '$password', '$email')";

And you should not rely on user input. It is good that you are already making new variables of the $_POST variables before using them, but you should prepare them for sending them into your database.

Check out how can i prevent sql injection in php