0

I was trying to get variable in Query String from URL. But somehow, its just got one variable instead of getting all variables from querystring. I really don't know what goes wrong with my code. Here is the code I want to print out error from the invalidate form:

<?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
 }
 ?>

And here is the code I created the querystring:

$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(); 

In the first code, the page only print the first $_GET['name_error'], while it should be include $_GET['date_error'] and $_GET['price_error. '] This is the address:

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+price+must+be+float+number+only

asked May 22, 2012 at 9:19

2 Answers 2

3

You should use & instead of &amp;'s ?

$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(); 
answered May 22, 2012 at 9:21
2
  • 1
    Yah, no need to HTML escape &s in a URL if they are being used for what they are supposed to be used for (separating data). Commented May 22, 2012 at 9:24
  • yEAH, I can see it now, that's my bad. Thank you so much, it's fixed :) Commented May 22, 2012 at 9:27
1

Change &amp; to & as:

$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(); 
answered May 22, 2012 at 9:25
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.