0

My error when I try to signup in my app, i get this erorr : Fatal error: Call to a member function bind_param() in C:...\signup.php on line 36

i am using Http Request in my ios app if you want to know!

What's wrong?

thnxs
php code

 <?php

    // Xx_mr.drama_xX

    header('Content-type: application/json');
    if($_POST) {
        $username   =mysql_real_escape_string($_POST['username']);
        $email =mysql_real_escape_string( $_POST['email']);
        $password   =mysql_real_escape_string( $_POST['password']);
        $phonenumper =($_POST['phonenumper']);

        if($_POST['username']) {
            if ( $password <=6  or  $password >=32 ) {

                $db_name     = 'posting';
                $db_user     = 'root';
                $db_password = 'root';
                $server_url  = 'localhost';

                $mysqli = new mysqli('localhost', $db_user, $db_password, $db_name);

                /* check connection */
                if (mysqli_connect_errno()) {
                    error_log("Connect failed: " . mysqli_connect_error());
                    echo '{"success":0,"error_message":"' . mysqli_connect_error() . '"}';
                } else {
                    //$stmt = $mysqli->prepare("INSERT INTO users (username, email, password , phonenumper)
                    // VALUES ( '$username' ,  '$email' , '$password' , '$phonenumper')";


                $stmt = mysqli_prepare($mysqli, "INSERT INTO users VALUES (?, ?, ?, ?)");
                mysqli_stmt_bind_param($stmt, 'sssd', $username, $email, $password, $phonenumper);

                     //"INSERT INTO `users`(`username`, `password`) VALUES ('".$username."', '".$password."')";
                    $password = md5($password);
                    $stmt->bind_param('sssd', $username, $password,$email,$phonenumper);

                    /* execute prepared statement */
                    $stmt->execute();

                    if ($stmt->error) {error_log("Error: " . $stmt->error); }

                    $success = $stmt->affected_rows;

                    /* close statement and connection */
                    $stmt->close();

                    /* close connection */
                    $mysqli->close();
                    error_log("Success: $success");

                    if ($success > 0) {
                        error_log("User '$username' created.");
                        echo '{"success":1}';
                    } else {
                        echo '{"success":0,"error_message":"Username Exist."}';
                    }
                }
            } else {
                echo '{"success":0,"error_message":"Password does not match."}';
            }
        } else {
            echo '{"success":0,"error_message":"Invalid Username."}';
        }
    }else {
        echo '{"success":0,"error_message":"Invalid Data."}';
    }
    ?>
Zakaria Sassi
  • 11
  • 1
  • 1
  • 5
  • you have both OOP and procedural version of bind param.. Choose 1 and stick with it. This double bind param is causing the error. – Matt May 29 '16 at 22:22
  • Is it intentional that "phonenumber" is spelled wrong in multiple places? Also, why is it not escaped like the other fields? Also, don't store a phone number as a number in SQL. – Chris May 29 '16 at 22:24
  • @Matt did not understand what you mean BRO – Zakaria Sassi May 29 '16 at 22:33
  • also you shouldn't use md5 if you can help it. Use phps built in hashing http://php.net/manual/en/faq.passwords.php – Matt May 29 '16 at 22:33
  • @ZekoBoss Procedural version: `mysqli_stmt_bind_param($stmt, 'sssd', $username, $email, $password, $phonenumper);` OOP Version: `$stmt->bind_param('sssd', $username, $password,$email,$phonenumper);` you have both of these.. you only need one. Since you prepared the statement procedurally, choose the procedural binding – Matt May 29 '16 at 22:34
  • Oh ok thank you my friend ^^ @Matt – Zakaria Sassi May 29 '16 at 22:40

0 Answers0