php和mysql學習筆記

來源:互聯網
上載者:User

標籤:

1、Undefined index: pwd in E:\xampp\htdocs\phpbase2elite\12\source\register.php on line 6

這是一個警告,表示數組下標為‘pwd‘未定義就在使用了
修改代碼:isset($_POST[‘username‘])?$_POST[‘username‘]:"";2、

2、防止sql注入
// 檢查用戶端提交的資料中是否含有非法字元function checkIllegalWord (){    // 定義不允許提交的SQL命令及關鍵字    $words = array();    $words[]    = " add ";    $words[]    = " count ";    $words[]    = " create ";    $words[]    = " delete ";    $words[]    = " drop ";     $words[]    = " from ";    $words[]    = " grant ";    $words[]    = " insert ";     $words[]    = " select ";    $words[]    = " truncate ";    $words[]    = " update ";    $words[]    = " use ";    $words[]    = "-- ";        // 判斷提交的資料中是否存在以上關鍵字, $_REQUEST中含有所有提交資料    foreach($_REQUEST as $strGot) {        $strGot = strtolower($strGot); // 轉為小寫        foreach($words as $word) {            if (strstr($strGot, $word)) {                echo "您輸入的內容含有非法字元!";                exit; // 退出運行            }        }    }// foreach}checkIllegalWord(); // 檢查非法字元

 

3、如何在phpmyadmin中新insert一條新資料,以及解決中文顯示亂碼的問題;

先選中你要插入的表格,再在sql中輸入下面這條語句:

insert into t_user(f_username, f_password, f_name, f_email) values (‘admin1‘, md5(‘123456‘), ‘管理員‘, ‘[email protected]‘);


但這時你會發現中文顯示“??”,亂碼,解決辦法:

進入欄位--->選擇亂碼的變數,點擊修改--->將其更改成”utf8_general_ci“,再向表中插入中文資料,不顯示亂碼了。

還有一種辦法就是:

在建立表的時候應該先添加欄位的編碼,在欄位類型後面添加”CHARACTER SET utf8 COLLATE utf8_general_ci“,比如SQL語句

create table webgrades(    班級 varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci,    學號 varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci,    姓名 varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci,    成績 int (3));

那麼CHARACTER SET utf8 COLLATE utf8_general_ci是幹什麼用的呢?

如果表的結構指定了CHARACTER SET X和COLLATE Y,那麼採用字元集X和校對規則Y。 如果指定了CHARACTER SET X而沒有指定COLLATE Y,那麼採用CHARACTER SET X和CHARACTER SET X的預設校對規則。 否則,採用預設的字元集和伺服器校對規則。

第三種辦法:點擊操作,改掉資料庫的預設編碼變為utf8_general_ci,這樣我們就不用一個個去改了

 4、drop、delete和truncate

drop是刪除表,使用drop之後表結構和表的資料都會被刪除,truncate 和 delete是刪除表裡的資料,但不刪除表本身,truncate 和 delete相比,truncate要快很多,但缺點就是不能復原,包括索引等都會變成初始值,資料就無法恢複了。

 5、Xampp中mysql傳來的中文資料亂碼

使用XAMPP的過程中,對於存入表中的中文,在phpmyadmin中查看發現全是亂碼,其實單純的在mysql中也是這樣,因為預設使用的是latin1的編碼格式。

       改一下mysql下的bin檔案下的my.ini檔案就可以實現使用utf8_general_ci編碼格式,這樣就能顯示中文了。

       在my.ini中添加下面一些東西:

[client]   default_character_set = utf8    [mysqld]  character-set-server = utf8  collation-server = utf8_general_ci  [mysql]  default_character_set = utf8  

        重啟mySQL,再次存入資料,發現沒有中文亂碼問題了。

 

6、 Notice: Undefined offset: 3 in E:\xampp\htdocs\phpbase2elite\15\bbs\TreeNode.php on line 50

Google結果:

The $numbers variable is not initialized, it needs to be declared before you can use it. For example $numbers = ‘‘; somewhere above the $decip = ...

就是說變數沒有初始化,在用的時候應該先初始化的。

 

 

 





php和mysql學習筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.