8.28php自學(xué)連接數(shù)據(jù)庫(kù)+搭建后臺(tái)頁(yè)面

<?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>';
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容