New users registered in php member management cannot be properly stored. Solution-php Tutorial

Source: Internet
Author: User
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);        }    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.