New users registered in php member management cannot be properly stored. 1. the processing code is as follows: & lt ;? Phpinclude (& quot; dbconnect. inc. php & quot;); include (& quot; functions. inc. php & quot;); # if magic_quotes_gpc is not set in php configuration, filter the string. $ Formcheck_form (new users registered in php member management cannot be properly stored
1. the processing code is as follows:
Include ("dbconnect. inc. php ");
Include ("functions. inc. php ");
# If magic_quotes_gpc is not set in php configuration, filter the string.
$ Form = check_form ($ _ POST ["edit"]);
$ Form ["reg_time"] = date ("Y-m-d H: I: s ");
$ Form ["pass"] = md5 ($ form ["pass"]);
Extract ($ form );
$ SQL = "insert into users (username, password, sex, mail, tel, web, birthday, inter, intro, reg_time )";
# Here the {} symbol represents the variable that references the current environment in the string
$ SQL. = "values ('{$ name }',";
$ SQL. = "'{$ pass }',";
$ SQL. = "'{$ sex }',";
$ SQL. = "'{$ mail }',";
$ SQL. = "'{$ tel }',";
$ SQL. = "'{$ web }',";
$ SQL. = "'{$ birthday }',";
$ SQL. = "'{$ inter }',";
$ SQL. = "'{$ intro }',";
$ SQL. = "'{$ reg_time }')";
$ Res = mysql_query ($ SQL );
If (! $ Res ){
Die ("database error, please return and try again. ");
}
Header ("Location: msg. php? M = register_success ");
?>
The primary cause is the fifth line.
$ Form = check_form ($ _ POST ["edit"]);
I tried it. when the program runs on this line, an error will occur, but no error will be reported. If '#' is added before this line, a message indicating that the storage is successful is displayed, however, there are only two fields in lines 6 and 7. please give us some advice. the following code contains the above.
2. dbconnect. inc. php code
Include ("settings. inc. php ");
# Connect to db
$ Con = mysql_connect ($ dbhost, $ dbuser, $ dbpass );
If (! $ Con) die ("mysql error:". mysql_error ());
Mysql_select_db ($ dbname, $ con );
?>
3. functions. inc. php code
Function check_form ($ form ){
If (! Get_magic_quotes_gpc ()){
For ($ I = 0; $ I $ Form [$ I] = addslashes ($ form [$ I]);
}
}
Return $ form;
}
?>
4. settings. inc. php code
# Mysql server IP address and database name
$ Dbhost = "localhost ";
$ Dbname = "book ";
$ Dbuser = "admin ";
$ Dbpass = "123456 ";
?>
------ Solution --------------------
Change the function check_form
PHP code
Function check_form ($ form) {if (! Get_magic_quotes_gpc () {foreach ($ form as $ I =>$ v) {$ form [$ I] = addslashes ($ v) ;}} return $ form ;}
------ Solution --------------------
Check_form should be recursive.
PHP code
public static function stripslashes($param) { if (is_array($param)) { foreach ($param as $k => $v) { $param[$k] = self::stripslashes($v); } return $param; } else { return stripslashes($param); } }