<?php
// 1:鏈接MySQL
mysql_connect('localhost','root','root');
// 2:選擇一個(gè)要操作的數(shù)據(jù)庫(kù)
mysql_select_db('cms');
// 3:設(shè)置字符集
mysql_set_charset('utf8');
?>
后臺(tái)頁(yè)面對(duì)接數(shù)據(jù)庫(kù):
<?php
header("content-type:text/html;charset=utf-8");
// echo '<pre>';
// 開啟session
session_start();
$username=$_POST['username'];
$pwd=md5($_POST['pwd']);
$vcode=strtolower($_POST['vcode']);
// 引入數(shù)據(jù)庫(kù)配置文件
include '../config.php';
// 2:定義sql語(yǔ)句
$sql="select * from web_user where username='$username'";
// 3:發(fā)送sql語(yǔ)句,接收反饋
$result=mysql_query($sql);
// 4:將返回值以索引數(shù)組形式顯示
$row=mysql_fetch_assoc($result);
// var_dump($row);
// exit();
if($vcode==strtolower($_SESSION['vcode'])){
if($username==$row['username'] && $pwd==$row['userpwd']){
echo '<script>alert("登錄成功!");window.location="indexed.php"</script>';
}else{
echo '<script>alert("帳號(hào)密碼不匹配,請(qǐng)重新輸入!");window.location="index.php"</script>';
}
}else{
echo '<script>alert("驗(yàn)證碼不正確,請(qǐng)重新輸入!");window.location="index.php"</script>';
}