1

I have a form in html with php code inside which looks like this

<form name="category" action="search.php" method="get" enctype="multipart/form-data">
    <select class="form-control2" name="category_name" id="category_name" onchange="category.submit();">
    <option value="0">Select Category</option>
      <?php while($cat_data=mysql_fetch_array($cat_res)){?>
      <option value="<?php echo $cat_data['Category_Name'] ?>"><?php echo $cat_data['Category_Name'] ?></option>
      <?php }?>
    </select>
</form>

With this I get URL like

 /search.php?category_name=USA

I want to add another field in URL so the URL look like

/search.php?cat_name=1&category_name=USA

This field cat_name must be updated from mysql and not from form in real time depending what option is selected. Is it possible in php and html

1
  • is there a column named cat_name in your data?ie, an index cat_name in $cat_data array?? Commented Oct 1, 2015 at 5:55

3 Answers 3

3

Two possible solutions - first add query string in action of form

<form name="category" action="search.php?cat_name=1"
 method="get" enctype="multipart/form-data">

Alternatively , append a input type hidden or as you need .

<form name="category" action="search.php" method="get" enctype="multipart/form-data">
    <select class="form-control2" name="category_name" id="category_name" onchange="category.submit();">
    <option value="0">Select Category</option>
      <?php while($cat_data=mysql_fetch_array($cat_res)){?>
      <option value="<?php echo $cat_data['Category_Name'] ?>"><?php echo $cat_data['Category_Name'] ?></option>
      <?php }?>
    </select>
<input type="hidden" name="cat_name" value="1" />
</form>
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Rohit. Thanks for your help
0

Just add a hidden input field before your closing form tag

<input type="hidden" name="cat_name" value="<?php echo cat_name; ?>" />

Comments

0

Use hidden input field in the form

<form name="category" action="search.php" method="get" enctype="multipart/form-data">
    <input type="hidden" name="name" value="1" />
</form>

Comments

Your Answer

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.