首页 > 编程知识 正文

mysqli登录页面实例,mysql制作登录界面

时间:2023-12-27 22:26:10 阅读:323794 作者:UMLC

本文目录一览:

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: %sn", mysqli_connect_error());

exit();

}

printf("Host information: %sn", $mysqli-host_info);

/* close connection */

$mysqli-close();

?

二、面向过程

?php

$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* check connection */

if (!$link) {

printf("Connect failed: %sn", mysqli_connect_error());

exit();

}

printf("Host information: %sn", 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']

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。