0

したがって、ASPからPHPを使用するのは比較的新しいです。そして、多くの ASP コードを PHP に変換した後、設定した隠し変数を PHP コードが見つけられないように見えるという問題に遭遇しました。ASP では問題なく動作し、これを解決する最善の方法を考えていました。

フォームの開始:

<form name="LogIn" action="login.php" method="post">
                    <td bgColor=#ffffff>
                        <table align="center" cellSpacing="2" cellPadding="2" border="0">
                            <tr>
                                <td>&nbsp;</td>
                                <td align="right"><font color="#4d71a1">User name:</font>&nbsp;</td>
                                <td><input name="UserName" size="25" type="Text" autocomplete="OFF"></td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td align="right"><font color="#4d71a1">Password:</font>&nbsp;</td>
                                <td><input name="Password" size="25" type="Password" autocomplete="OFF"></td>
                                <td>&nbsp;</td>
                            </tr>

PHP スクリプト:

<? 
if ($_POST["BtnPress"]=="Pressed")
{

if ($_POST["Username"]=="*****" && $_POST["password"]=="*********")
{

$_SESSION['AdminID']="1";
header("Location: "."index.php");
}
  else
{

print "<font color=#ff0000>Sorry you cannot access this part of the site.</font>";
} 

} 
?> 

次に、フォームの残りの部分:

<tr>
                                <td align="center" colspan="4">
                                    <input type="hidden" name="BtnPress" value="Pressed">
                                    <input type="Submit" value="Log In" class="mybutton" onclick="return CheckForm();">
                                </td>   
                            </tr>
                        </table>


                    </td>
                </form>

PHP は変数 BtnPress を見つけることができないようです。これは、ASP から PHP への変換スクリプトの多くで同様の問題です。単純な解決策であれば申し訳ありませんが、どこが間違っているのか教えてもらえますか?

4

3 に答える 3

4

You have name="Password" and $_POST["password"]

Password != password

Watch your case.


<form name="LogIn" action="login.php" method="post">
                    <td bgColor=#ffffff>

That is invalid HTML. A <td> element cannot be a child element of a <form>. Browsers are likely to error recover in ways that break your HTML (e.g. by moving the form, but not its contents, outside the table). Do use a validator.


And stuff that isn't likely to be the cause of the problem, but is likely to be the cause of other problems.

  • Don't use layout tables
  • Do use the label element
  • Do use CSS for presentation (you can style your label elements instead of using the obsolete font element
于 2012-09-03T08:21:15.427 に答える
1

フォームが送信されたかどうかをテストするために非表示の入力を使用しないでください。

使用する:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  // processing of $_POST
}
于 2012-09-03T08:24:17.613 に答える
0

送信ボタンの名前は、隠しフィールドではなく「BtnPressed」にする必要があります。私がすることは、フォームアクションを ?id=submit などに設定してから、「if $_GET['id'] == "submit"」をチェックしてからデータを処理することです。

<form action="login.php?do=submit">

....  <input ..... 

</form>
<?php
if($_GET['do'] == "submit"){

//process data

} ?>
于 2012-09-03T08:22:39.990 に答える