4

Hi I have a class called User and a method called insertUser().

function insertUser($first_name, $last_name, $user_name, $password, $email_address, $group_house_id)
  {
    $first_name = mysql_real_escape_string($first_name);
    $last_name = mysql_real_escape_string($last_name);
    $user_name = mysql_real_escape_string($user_name);
    $password = mysql_real_escape_string($password);
    $email_address = mysql_real_escape_string($email_address);

    $query = "INSERT INTO Users
              (FirstName,LastName,UserName,Password,EmailAddress, GroupHouseID) VALUES
              ('$first_name','$last_name','$user_name','$password','$email_address','$group_house_id')";
    $mysql_query($query);
  }

And I call it like this:

$newUser = new User();
$newUser->insertUser($first_name, $last_name, $user_name, $email, $password,          $group_house_id);

When I run the code I get this error:

Fatal error: Function name must be a string in /Library/WebServer/Documents/ORIOnline/includes/class_lib.php on line 33

Anyone know what I am doing wronly? Also, this is my first attempt at OO PHP.

Cheers,

Jonesy

0

3 Answers 3

16

$mysql_query($query); => mysql_query($query);. Note the missing dollar. If you try to use function call syntax on a variable, it looks for a function with the name given by the value of the variable. In this case, you don't have a mysql_query variable, so it comes back with nothing, which isn't a string, and thus gives you the error.

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

Comments

3

You have a stray $ on mysql_query. Remove it:

mysql_query($query);

Comments

0

Just for the next newbie, another example of how this error

" PHP Fatal error: Function name must be a string in ..."

is triggered / and solved is as below;

Say you have an associative array;

$someArray = array ( 
                 "Index1" => "Value1",
                 "Index2" => "Value2",
                 "Index3" => "Value3"
              );

echo $someArray('Index1'); // triggers a fatal  error as above

Solution:

echo $someArray['Index1']; // <- square brackets - all good now

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.