我正在寫一個代碼,用於在mysql數據庫上註冊表單和數據查詢。在註冊表單是在這裏: -註冊系統不工作在PHP和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);
現在,當我在我的瀏覽器通過本地主機打開的index.php,它顯示錯誤: -
Fatal error: Call to undefined function check_data() in C:\xampp\htdocs\oop\user_reg\index.php on line 145
但是,我已經有一個名爲check_data()的函數,並且該函數本身運行良好。但是我的代碼發生了不好的事情。我想修復它並無法做到。我很需要你們的幫助。謝謝。
MD5不是安全的前正是推動這一功能。你應該使用bcrypt。 – SLaks