php會員管理中註冊新使用者不能正確儲存解決辦法

來源:互聯網
上載者:User
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;}
------解決方案--------------------
check_form要是個遞迴吧
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);        }    } 
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.