从不工作的PHP注册 - mysqli->查询

时间:2015-06-13 04:59:47

标签: php mysqli dreamweaver

 <?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> 

这是我的代码,当我点击注册按钮时,我给了我这个错误

  

“致命错误:在第112行的C:\ wamp \ www \ Unnamed Site 2 \ Signup.php中的非对象上调用成员函数query()”

我仍然是这个PHP STUFF的新手需要帮助!

ASLO当我尝试连接我的DATBASE THRU DREAMWEAVER时给我一个错误的说法,那就是没有任何数据显示

感谢提前

1 个答案:

答案 0 :(得分:2)

调用成员函数query()意味着您正在尝试使用名为query的函数,该函数不作为php或用户定义的函数存在。

你的变量$ query不应该有()。这用于调用函数。

只使用$ query =“你的SQL查询”;

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

您不应该依赖用户输入。在使用$ _POST变量之前,你已经在制作$ _POST变量的新变量,这很好,但你应该准备好将它们发送到数据库中。

查看how can i prevent sql injection in php