调用未定义的函数create_user()

时间:2015-01-20 19:59:00

标签: php

编程经验非常有限,因此试图了解以下错误背后的原因。

我收到错误:

  

致命错误:在第20行的/home/kxxxxxx/www/test_db_functions.php中调用未定义的函数create_user()

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, 2buzz@disney.com"); // Am receiving error on this line (Line 20)
create_user ($mysqli, 'Woody', '056789', 'woody@disney.com');
print_users ($mysqli);
delete_user_by_id ($mysqli, 1);
delete_user_by_email ($mysqli, 'woody@disney.com');
print_users ($mysqli);

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

2 个答案:

答案 0 :(得分:1)

检查线:

create_user ($mysqli, "Buzz", "0123452, 2buzz@disney.com"); // Am receiving error on this line (Line 20)

代替:

create_user ($mysqli, "Buzz", "0123452", "2buzz@disney.com");

PHP正在寻找带有3个参数的create_user函数,你的行有一个拼写错误,可以通过这种方式进行调用,但你已经定义了一个4参数函数。

答案 1 :(得分:1)

问题在这里

create_user ($mysqli, "Buzz", "0123452, 2buzz@disney.com");

创建用户需要4个参数,但是你只给它3个,那些是

1 = $ mysqli的

2 = “嗡嗡”

3 =“0123452,2buzz@disney.com”

找不到只有3个参数的函数,并发布错误。