php会员管理中注册新用户不能正确存储解决办法

WBOY
Release: 2016-06-13 13:37:39
Original
1047 people have browsed it

php会员管理中注册新用户不能正确存储
1、处理代码如下:
include("dbconnect.inc.php");
include("functions.inc.php");
#如果php配置中,magic_quotes_gpc没有被设置,则执行过滤字符串。
$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) ";
#这里{}符号是代表在字符串中引用当前环境的变量
$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("数据库出错,请返回重试。");
}

header("Location:msg.php?m=register_success");
?>
主要是出问题在第五行
$form = check_form($_POST["edit"]);
我试了,程序运行到这一行就会出错,但又不报错,如果在这一行前加‘#’,则提示存储成功,但只有6、7行的两个字段,请各位大虾不吝赐教,以下为以上包含使用的代码。
2、dbconnect.inc.php代码
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代码
function check_form($form) {
if(!get_magic_quotes_gpc()) {
for($i=0;$i $form[$i] = addslashes($form[$i]);
}
}
return $form;
}
?>
4、settings.inc.php代码
#mysql服务器IP及数据库名
$dbhost = "localhost";
$dbname = "book";
$dbuser = "admin";
$dbpass = "123456";
?>


------解决方案--------------------
函数check_form改为

PHP code
function check_form($form) {
  if(!get_magic_quotes_gpc()) {
    foreach($form as $i=>$v) {
       $form[$i] = addslashes($v);
    }
  }
  return $form;
}
<br><font color="#e78608">------解决方案--------------------</font><br>check_form要是个递归吧<br>
Copy after login
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);
        }
    } <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!