注册系统无法在php和mysql中工作[致命错误]


sign up system not working in php and mysql [Fatal Error]

我正在为mysql数据库上的注册表单和数据查询编写代码。注册表格在这里:-

<form action="index.php" method="POST" enctype="multipart/form-data">
    First Name:<input type="text" name="name"><br>
    Last Name : <input type="text" name="lname"><br>
    Username : <input type="text" name="uname"><br>
    Password : <input type="text" name="password"><br>
    age : <input type="text" name="age"><br>
    Email : <input type="text" name="email"><br>
    Chose_Images : <input type="file" name="images"><br>
    <input type="submit" name="submit">
</form>

现在,index.php文件在这里:-

<?php
require'store.inc.php';
if (isset($_POST['submit'])) {
    # code...

$first_name = mysql_real_escape_string(htmlentities($_POST['name']));
$last_name = mysql_real_escape_string(htmlentities($_POST['lname']));
$username = mysql_real_escape_string(htmlentities($_POST['uname']));
$password = mysql_real_escape_string(htmlentities($_POST['password']));
$password_hash = md5($password);
$age = mysql_real_escape_string(htmlentities($_POST['age']));
$email = mysql_real_escape_string(htmlentities($_POST['email']));
    if (isset($first_name) && isset($last_name) &&isset($username) &&isset($password) &&isset($age) &&isset($email)) {
        # code...
            if (!empty($first_name) && !empty($last_name) &&!empty($username) &&!empty($password) &&!empty($age) &&!empty($email)) {

        $errors = array();

// cheking string limit............
        if (strlen($first_name) > 50) {
            # code...
            $errors[] = 'PLease dont cross the strign limit in first name colum'.'<br>';
        }elseif (strlen($last_name) > 50) {
            # code...
            $errors[] = 'PLease dont cross the strign limit in first name colum'.'<br>';
        }elseif (strlen($username) > 50) {
            # code...
            $errors[] = 'Your username is out of string limit'.'<br>';
        }elseif (strlen($password) > 40) {
            # code...
            $errors[] = 'Your password is too long';
        }elseif (strlen($age) > 50) {
            # code...
            $errors[] = 'you can not register into the site';

        }elseif (strlen($email) > 50) {
            # code...
            $errors[] = 'You are out of Email string limit';
        }
// coding of the first function start...
        function connect_database(){
            $server_connect = mysql_connect('localhost','root','');
            $server_database = mysql_select_db('reg_log',$server_connect);
                            if ($server_connect && $server_database) {
                                # code...
                                            return true;
                                } else {
                                        return false;
                                                }
                                            }
// coding of the first function END...........

// coding of the function check_data() start...
function check_data(){
    global $username;
        connect_database();
        $select = "SELECT `username` FROM `users` WHERE `username` = '$username'";
        $select_query = mysql_query($select);
        $num_rows = mysql_num_rows($select_query);
        if ($num_rows == 1) {
            # code...
            return false;
        } elseif ($num_rows == 0) {
            # code...
            return true;
        }
}
//coding of the function End..................
// *********Varibles about Images which will be Global varibles..........Using addslashes for security
$image = addslashes(file_get_contents($_FILES['images']['tmp_name']));
$image_name = addslashes($_FILES['images']['name']);
$image_size = addslashes(getimagesize($_FILES['images']['tmp_name']));

//*******Varible Stored.....................................................
//Coding of Inserting Data in the database...By this function code will insert data in to database after all check...........
function insert_data(){
global $first_name,$last_name,$username,$password_hash,$age,$email,$images;
    connect_database();
    $insert = "INSERT INTO users VALUES('','$first_name','$last_name','$username','$password_hash','$age','$email','$images')";
    $insert_query = mysql_query($insert);
    if ($insert_query) {
        # code...
        return true;
    }
}

        }
        }
}
    if (empty($errors)) {
        # code...
        if (check_data()) {
            # code...
            insert_data();
        }
    }else{
        foreach ($errors as $error) {
            # code...
            echo $error.'<br>';
        }
            }


?>

两个文件都相同。我的意思是,这两个代码存储在同一个名为"index.php"的文件中。"store.inc.php"只包含:-

$server_connect = mysql_connect('localhost','root','');
$server_database = mysql_select_db('reg_log',$server_connect);

现在,当我在浏览器中通过localhost打开index.php时,它显示了一个错误:-

Fatal error: Call to undefined function check_data() in C:'xampp'htdocs'oop'user_reg'index.php on line 145

但是,我已经有了一个名为check_data()的函数,并且该函数本身运行良好。但是我的代码出了问题。我想把它修好,但做不到。我急需你们的帮助。非常感谢。

您在if下使用此函数check_data(),然后从if.外部调用它

试着把这个函数移到这行之前

      if (empty($errors)) {
    # code...
    if (check_data()) {