0

URLからクエリ文字列の変数を取得しようとしていました。しかし、どういうわけか、クエリ文字列からすべての変数を取得するのではなく、1つの変数を取得しただけです。私は自分のコードで何がうまくいかないのか本当にわかりません。無効化フォームからエラーを出力したいコードは次のとおりです。

<?php       
            displayForm();
            function displayForm(){
                ?>                    
                <form action="./prod_add_action.php" method="post" name="addproductForm">
                    <fieldset>
                        <legend>Online Ordering System Setup</legend>                        
                        <label for="product_name">Product Name: </label><input type="text" name="product_name" value="" /><?php echo $_GET["name_error"]; ?>
                        <label for="product_date">Product Date: </label><input type="text" name="product_date" value="" /><?php echo $_GET["date_error"]; ?>
                        <label for="product_price">Product Price: </label><input type="text" name="product_price" value="" /><?php echo $_GET["price_error"]; ?>
                        <input name="add_button" type="submit" value="Add" />
                        <input name="reset_button" type="reset" value="Clear" />
                    </fieldset>
                </form>
                <?php
            }
            ?>

そして、これが私がクエリ文字列を作成したコードです:

$query_string = "name_error=" .urlencode($name_error) ."&amp;date_error=" .urlencode($date_error) ."&amp;price_error=" .urlencode($price_error);
            header("Location: ./prod_add.php?$query_string");
            exit();             

最初のコードでは、ページは最初の$ _GET ['name_error']のみを出力しますが、$ _GET['date_error']と$_GET['price_errorを含める必要があります。']これはアドレスです:

http://example.com/prod_add.php?name_error=Product+name+must+be+characters+only&date_error=Product+date+must+be+input+as+this+formate+DD-MM-YYYY&price_error=Product+価格+必須+be+ float + number + only

4

2 に答える 2

3

&の代わりに使用する必要があります&amp;か?

$query_string = "name_error=" .urlencode($name_error) ."&date_error=" .urlencode($date_error) ."&price_error=" .urlencode($price_error);
            header("Location: ./prod_add.php?$query_string");
            exit();   
于 2012-05-22T09:21:50.920 に答える
1

次のように変更&amp;&ます。

$query_string = "name_error=" . urlencode($name_error) . "&date_error=" . urlencode($date_error) . "&price_error=" . urlencode($price_error);
header("Location: ./prod_add.php?$query_string");
exit();  
于 2012-05-22T09:25:58.130 に答える