ednaaard
ednaaard

Reputation: 15

Call to undefined function create_user()

Very limited programming experience so trying to understand the reasoning behind the following error.

I'm receiving the error:

Fatal error: Call to undefined function create_user() in /home/kxxxxxx/www/test_db_functions.php on line 20

db_functions.php

<? php
function print_users ($db_con) 
{}
function create_user ($db_con, $Name, $Phone, $Email) 
{}
function delete_user_by_id ($db_con, $ID) 
{}
function delete_user_by_email ($db_con, $Email) 
{}
?>

test_db_functions.php

<!DOCTYPE html>
<html>
    <head>
        <title>Test DB Functions</title>

    </head>
    <body>
<?php
require 'db_functions.php';
$mysqli = new mysqli("server name", "username", "password", "db name");
if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: " . $mysqli->connect_error;
} 

create_user ($mysqli, "Buzz", "0123452, [email protected]"); // Am receiving error on this line (Line 20)
create_user ($mysqli, 'Woody', '056789', '[email protected]');
print_users ($mysqli);
delete_user_by_id ($mysqli, 1);
delete_user_by_email ($mysqli, '[email protected]');
print_users ($mysqli);

$mysqli->close();
?>
    </body>
</html>

Upvotes: 1

Views: 1047

Answers (2)

Check the line:

create_user ($mysqli, "Buzz", "0123452, [email protected]"); // Am receiving error on this line (Line 20)

instead do:

create_user ($mysqli, "Buzz", "0123452", "[email protected]");

PHP is looking for the create_user function with 3 parameters, your line has a typo that makes the call that way, but you have defined a 4 parameter function.

Upvotes: 1

Dimitri
Dimitri

Reputation: 453

Issue is here

create_user ($mysqli, "Buzz", "0123452, [email protected]");

Create user expects 4 arguments, but you are giving it only 3, those being

1=$mysqli

2="Buzz"

3="0123452, [email protected]"

It cannot find a function with only 3 params, and posts an error.

Upvotes: 1

Related Questions