my supermarket error

一、PHP實現添加mysql數據時,若是字段中含有中文,刷新時php不會報錯,數據不會添加到數據庫?php

緣由:Incorrect string value: '\xD6\xD0\xB9\xFA\xB1\xEA...' for column 'VARIABLE_VALUE' at row 1html

         一、自增的話,能夠省略字段。mysql

         二、 典型的字符編碼不一致問題jquery

解決:show variables like '%char%';show create table tbname;  查看字符集是否一致。ajax

        重要在con鏈接數據庫設置:mysql_select_db("dch_db",$con);
                                               mysql_query("set names gb2312");sql

        請求PHP 頁:<meta http-equiv="Content-Type" content="text/html; charset=gdk" />數據庫

 

<?php
 $con=mysql_connect("localhost","root","123456");
 if(!$con){
 echo "conection fail!".mysql_error();
 }
 mysql_select_db("dch_db",$con);
 mysql_query("set names gb2312");
?>session

<?php
 session_start();
 include_once("conn.php");
 //echo $_REQUEST[user];
?>post

 二、要求對數據庫的用戶密碼加密?學習

解決:$pass = $_POST[pass];
   //對密碼MD5加密
    $pass = md5($pass);
$sql="select count(*) from tb_user where username='".$name."' and password='".$pass."' and display='管理員'";
//執行sql語句
$result=mysql_query($sql,$link);
數據字符長度設密碼長度爲32,

註冊:<?php
if ( $_POST["submit"] <> "" )
{
include("config.php");
$pass = isset($_POST['password']) ? $_POST['password'] : '';
echo $md5_password=md5($pass . ALL_PS);
$sql="insert into user_list (id,m_id,username,password)
    values (null,'2','".$_POST["username"]."','".$md5_password."')";
   mysql_query($sql);
}
?>
<p>sign up</p>
<form action="" method ="post">
user:<input type="text" name="username"  /><br/><br />
passward:<input type="text" name="password" /><br /><br />
<input type="submit" name ="submit" value ="signup" />
</form>

 3ajax jquery 學習路徑:http://hi.baidu.com/yflife/item/9655f50e2301dbca74cd3c9d 

相關文章
相關標籤/搜索