0

私がやろうとしているのは、送信をクリックする前にユーザーが数量を入力していることを確認することです。問題は、ユーザーが数量ボックスに数値を入力しなくてもログイン画面に進むことができることです。検証コードを貼り付けてみましたが、引き続き login.php 画面が表示されます。どんな助けでも大歓迎です!

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>

        <form action='login.php' method='post'> 

        <?php


//The following arrays contain my products and their information, one product per array.

$hulkhamburger = array('Food' => 'Hulk Hamburger', 'Description' => '...', 'Price' => '$1.00', 'Quantity' => '<input type="text" name="quantity">');
$atomichotdog = array('Food' => 'Atomic Hot Dog', 'Description' => '...', 'Price' => '$2.00', 'Quantity' => '<input type="text" name="quantity">');
$friedchicken = array('Food' => 'Fantastic 4 Fried Chicken', 'Description' => '...', 'Price' => '$3.00', 'Quantity' => '<input type="text" name="quantity">');
$psyonicpizza = array('Food' => 'Psyonic Pizza', 'Description' => '...', 'Price' => '$4.00', 'Quantity' => '<input type="text" name="quantity">');
$marvelmeatloaf = array('Food' => 'Marvel Meatloaf', 'Description' => '...', 'Price' => '$5.00', 'Quantity' => '<input type="text" name="quantity">');

//The following array takes my previous five arrays and puts them into one array for easier coding and reading.

$allfood = array ($hulkhamburger, $atomichotdog, $friedchicken, $psyonicpizza, $marvelmeatloaf);

/*The following code centers my table on the page, makes the table background white,
 makes the table 50% of the browser window, gives it a border of 1 px,
 gives a padding of 2 px between the cell border and content, and gives 1 px of spacing between cells.
 */

echo "<table align=center bgcolor='FFFFFF' width=50% border=1 cellpadding=1
cellspacing=2>";

/*The following code prints my table header.
 * Credit goes to Dr. Kazman; code is from Lecture 10.
 * I used his code because it was easier (and a more efficient way) than doing it all manually like I did for Mini Asst. 2.
 */

echo "<tr>";
$header = array_keys($hulkhamburger);
foreach ($header as $key => $myheader)
{
    echo "<th>$myheader</th>";  
}
echo "</tr>";

//The following code loops through the whole table body and then prints each row.
for($i=0; $i<count($allfood); $i++)
    {
    echo "<tr>";
    foreach ($allfood[$i] as $key => $value)
        {
        echo ("<td align=center>$value</td>");
        }
    }        
//This code ends my table.
echo "</align>";
echo "<br>";   
        ?>
 <tr>
 <td>
 <td>
 <td>
 <td>
 <center><input type='submit' value='submit'></center>   
        </form>
    </body>
</html>

そして、これは私のlogin.phpです

<?php//made the user login menu into a nice table that will center the username and password in the middle of the page.?>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">

    <tr>
<form name="login" method="post" action="invoice.php">
    <td>

<table width="100%" border="0" cellpadding="3" cellspacing="1">
    <tr>


    <td colspan="3"><strong>User Login </strong></td>
    </tr>
    <tr>
    <td width="78">Username</td>
    <td width="6">:</td>    
    <td width="294"><input name="myusername" type="text" id="myusername"></td>
    </tr>
    <tr>
    <td>Password</td>
    <td>:</td>
    <td><input name="mypassword" type="text" id="mypassword"></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type='submit' name='login' value='Login'>

<?php
 /*This code will allow a new user to go to the registration page and register for the site
 * before buying anything.
 */
?>
<a href="registration.php"><br>New user registration</a>
    </td>
    </tr>
    </table>
    </td>
</form>
    </tr>
</table>
4

2 に答える 2

1

ユーザーを移動する

header("Location: http://www.google.de");

フォームで指定したページは検証を行う必要があります。ユーザーを login.php に直接送信し、検証が失敗した場合にユーザーを送り返すか、index.php が検証を実行し、検証が成功するとユーザーを login.php に送信するか、送信する 3 番目のスクリプトを作成します。ユーザーを 2 つのページのいずれかに移動します。

サーバーに値を渡す前に値を確認したい場合は、Javascript を使用してください。

JS を自分でコーディングしたくない場合は、フレームワーク (YII など) を使用してください。

于 2013-11-05T00:24:37.817 に答える