本文目錄一覽:
- 1、html+php+mysql的登錄頁面
- 2、PHP中為什麼mysqli需要實例化,而mysql不需要?
- 3、我是用PHP Mysql實現登錄的,怎樣在登陸後由登陸界面跳轉到index.html主頁面並在登陸的地方顯示用戶名
html+php+mysql的登錄頁面
header(“Content-Type: text/html; charset=utf-8”);
$lune=$_POST[“username”];
$lpwd=$_POST[“password”];
include(“conn.php”);
$query = “select * from userlist where username = ‘$lune’ and password = ‘$lpwd'”;
$result = mysqli_query($link, $query);
if (mysqli_num_rows($result) == 1){
$row = mysqli_fetch_array($result);
$json = array(‘lzhuangtai’ =’y’,’lname’ =$lune,’ldianhao’ =$row[phone], ‘ltishi’ =’用戶驗證成功’);
}
else{
$json = array(‘lzhuangtai’ =’n’,’ltishi’ =’用戶名或密碼無效’);
}
$json_string = json_encode($json);
echo $json_string;
你的代碼,$row[‘phone’]這裡是單引號,外邊也是,所以就出錯了。直接不用引號,或者換成雙引號。
PHP中為什麼mysqli需要實例化,而mysql不需要?
mysqli也不一定需要實例化,之所以你要實例化是因為你是要以面向對象的方式來開發這個程序,但是你要是用面向過程的方式來寫也是可以的,百度裏面有例子你可以看一下
一、面向對象
?php
$mysqli =new mysqli(“localhost”, “my_user”, “my_password”, “world”); //實例化對象
/* check connection */
if (mysqli_connect_errno()) {
printf(“Connect failed: %s\n”, mysqli_connect_error());
exit();
}
printf(“Host information: %s\n”, $mysqli-host_info);
/* close connection */
$mysqli-close();
?
二、面向過程
?php
$link = mysqli_connect(“localhost”, “my_user”, “my_password”, “world”);
/* check connection */
if (!$link) {
printf(“Connect failed: %s\n”, mysqli_connect_error());
exit();
}
printf(“Host information: %s\n”, mysqli_get_host_info($link));
/* close connection */
mysqli_close($link);
?
我是用PHP Mysql實現登錄的,怎樣在登陸後由登陸界面跳轉到index.html主頁面並在登陸的地方顯示用戶名
通常來說, index 頁面與 login 頁面被設計成兩個頁面,當通過 mysql 查詢數據,並驗證成功登錄後,可以自動轉向 index 頁面(或其他頁面):
if($num){
$row=mysql_fetch_array($result);
$_SESSION[“username”]=$uuser;
header(“Location:index.html”);
在 index 頁面需要添加代碼:例如:
?php
session_start();
//檢測是否登錄,若沒登錄則轉向登錄界面
if(!isset($_SESSION[‘username’])){
header(“Location:login.html”);
exit();
}
echo ‘當前登錄用戶:’ . $_SESSION[‘username’]
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/270832.html