dtwupu6414 2012-06-06 07:53
浏览 50
已采纳

PHP登录验证在同一页面上?

Could anyone explain me how to check and register username and password in the same page?

How can I echo the "wrong username and password" message in the form?

Thanks in advance.

Check Login

$result=mysql_query($sql);
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
  // Register $myusername, $mypassword and redirect to file "login_success.php"
  session_register("myusername");
  session_register("mypassword");
  header("location:login_success.php");
}
else {
  echo "Wrong Username or Password";

FORM

<form class="clearfix" name="form1" method="POST" action="">
  • 写回答

5条回答 默认 最新

  • douluo5937 2012-06-06 08:00
    关注

    Set the form action to the current .php file. In the script, check whether you already submitted the form (e.g. the submit button has a value in $_POST)

    If there is an answer, proceed with the login code. If no, create a new variable, like $errorMessage. Echo this error message somewhere in the form. (If this is time first time the user loads the script, there will be nothing in this variable, thus it will display nothing.)

    It'd be more elegant if you put the echo of $errorMessage in an if statement with some <div>s or whatever you'd like to use for this task.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥50 远程桌面打开Mastercam、没有许可证、物理机打开正常
  • ¥15 ubuntu安装gdal后java读取tif文件报错
  • ¥15 请问lammps怎么做两种金属连接的原子浓度分布图
  • ¥15 求jacquard数据集
  • ¥15 w10部分软件不能联网
  • ¥15 关于安装hbase的问题(操作系统-windows)
  • ¥15 novnc连接pve虚拟机报错安全协议不支持262
  • ¥15 设备精度0.03给多少公差能达到CPK1.33
  • ¥15 qt+ffmpeg报错non-existing PPS 0 referenced
  • ¥50 MacOS 使用虚拟机安装k8s