[PHP]10.實作:前端表單輸入後-送往後端處理

  • 3882
  • 0
  • PHP
  • 2022-12-03

文、意如

 

實作:

 

前端:a.php

使用者輸入 姓名、帳號、密碼

 

後端:b.php

預設帳號:abc123

預設密碼:123abc

判斷使用者輸入帳號密碼是否正確


a.php

 

 

 

 

 

 

 

b.php

登入成功

 

 

 

 

 

登入失敗

 

 

 

 

 

 

程式碼參考:

a.php

<html>
<head>
<title>123</title>
</head>
<body>
<form action="b.php" method="post">
姓名:<input type="text" name="myname" required><br>
帳號:<input type="text" name="myaccount" required><br>
密碼:<input type="password"name="mypwd" required><br>
<input type="submit">
</form>

</body>
</html>

a.php參考

b.php

<?php
$myname = $_POST["myname"];
//echo $myname;
$myaccount = $_POST["myaccount"];
//echo $myaccount;
$mypwd = $_POST["mypwd"];
//echo $mypwd;

$acc = "abc123";
$pwd = "123abc";


if ($acc == $myaccount && $pwd == $mypwd) {
	echo "成功登入" . $myname . "您好";
} else {
	echo "登入失敗";
}

b.php參考

 

 

Yiru@Studio - 關於我 - 意如