我正在为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()的函数,而且单独的函数运行良好。但是我的代码发生了一些不好的事情我想解决它而无法做到。我非常需要你的帮助。谢谢。
答案 0 :(得分:1)
您在if下使用此功能check_data()
,然后从if外部调用它。
尝试在此行之前准确移动此功能
if (empty($errors)) {
# code...
if (check_data()) {