2

How come I kept receiving this errror when I am using this mysqli_real_escape_string()?

mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\beatbeast\reg.php on line 6

I already pass the connection, and the strings that are needed to be sanitize, but how come i keep on getting that error?

here's my code

<?php
    class Db_DatabaseUtilities{

        public static function registerAccount($conn,$username,$password,$email){
            if(!isset($conn)){
                    echo"XDDDDDDDDD";
            }
            $username = mysqli_real_escape_string($conn,$username);
            $email =mysqli_real_escape_string($conn,$username);
            $password = mysqli_real_escape_string($conn,$password);
            $hashedpass = crypt($password,$username);

            $sql = "INSERT INTO accounts ('username','password','email') VALUES('{$username}','{$hashedpass}','{$email}')";
            Db_DatabaseUtilities::perform_query($conn, $sql);
        }

        public static function perform_query($conn,$sql){
            $result_set = $conn->query($sql);
            if(!$result_set){
                die("Die Database Query Failed");
            }else{
                return $result_set;
            }
        }       
    }

2 Answers 2

3

first: if this is your real code you are escaping $username twice and $email not at all:

$username = mysqli_real_escape_string($conn,$username);
$email =mysqli_real_escape_string($conn,$username);//should probably be $email as second param

you have an option of two problems:

  1. you have a bad database connection...check your connection and make sure it has the encoding set.
  2. you have bad input data...one of your parameters may not be a valid string

I can't see any other options... Good Luck

Sign up to request clarification or add additional context in comments.

Comments

0

Check the line 6 of reg.php.

string mysqli_real_escape_string ( mysqli $link , string $escapestr )

You need to pass the mysqli connection as the first parameter.

2 Comments

echo"XDDDDDDDDD"; that's line 6
@user962206 Is the file reg.php ? line 6 don't have mysqli_real_escape_string

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.