Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP登录验证是否在同一页面上?_Php_Html - Fatal编程技术网

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

PHP登录验证是否在同一页面上?,php,html,Php,Html,谁能解释一下如何在同一页中检查和注册用户名和密码 如何在表单中回显“错误的用户名和密码”消息 提前谢谢 检查登录名 $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

谁能解释一下如何在同一页中检查和注册用户名和密码

如何在表单中回显“错误的用户名和密码”消息

提前谢谢

检查登录名

$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 class="clearfix" name="form1" method="POST" action="">

真正的基础

   if(isset($_POST["submit"])){
     // user have submitted the form , proceed checking username/password and then start session
    }else{
     // display login form
    }

要显示错误,请创建一个变量
$error=“错误的用户名或密码”

然后在表格底部写下:

if(isset($error)) {
    echo $error;
}

将表单操作设置为当前的.php文件。在脚本中,检查您是否已提交表单(例如,提交按钮在
$\u POST
中有一个值)

如果有答案,请继续输入登录代码。如果否,则创建一个新变量,如
$errorMessage
。在表单中的某个位置回显此错误消息。(如果这是用户第一次加载脚本,则此变量中不会有任何内容,因此它不会显示任何内容。)


如果您将$errorMessage的回显放在带有一些
或您希望用于此任务的任何内容的if语句中,会更加优雅。

使用
isset
isempty
检查返回的数据

if(isset($_POST["formvariable"]))
{ }

同样在表单字段中,将action更改为
“currentfilename.php”

,我建议使用Ajax方法。最终的结果更加清晰。

您可以从查看教程开始,您应该使用Ajax方法将数据发送到服务器。@fluminis您能找到使用pdo的教程吗?:)为什么要为Zend framework和cakephp标记它?true添加了isset()以避免这种情况