本文目录一览:
- html+php+mysql的登录页面
- PHP中为什么mysqli需要实例化,而mysql不需要?
- [我是用PHP Mysql实现登录的,怎样在登陆后由登陆界面跳转到index.html主页面并在登陆的地方显示用户名](#我是用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'];