1.在連接數據庫時,基本會執行這三步:
mysqli_select_db($conn,'blog'); //選擇數據庫
$retval = mysqli_query($conn,$sql); //執行sql語句
$row = mysqli_fetch_assoc($retval); //提取數組
$row[username];// 爲username字段的值
2.在登錄form表單提交之前判斷text數值是否爲空 用onsubmit
<script type="text/javascript">
function check(){
if(document.getElementById('username').value==""&&document.getElementById('password').value==""){
alert('not null');
return false;
}
return true;
}
</script>
<form action="" method="post">
用戶名:<input type="text" id="username" name="username" />
密 碼:<input type="text" id="password" name="password" />
<input type="submit" value="Submit" />
</form>
3.這一點困擾了我很久,查了好多資料,問題就是,當一個頁面setcookie了之後,另一個頁面無法讀取到cookie,究其原因是路徑問題,應該是setcookie("user", $user, time()+3600,'/'); 後面要有一個‘/’,此路徑需要在你要訪問的文件的上一級,如存cookie到 /blog1/View 那麼/blog1/View/index.php就可以讀的到,/blog1/Controller/index.php就讀不到。