-3

I can not find nothing on internet about getting category id in url, so I post here.

I want an url like this : localhost/index.php&cat=1 , when I press submit button.

I use this code:

<form method="post" id="categories">
<select name="category">
<option value="">Select a category</option>
<?php
getCats();
?>
</select>
<button type="submit" form="categories" value="Submit">Submit</button>
</form>

and getcats:

function getCats(){
global $con;
$get_cats = "select * from category";
$run_cats = mysqli_query($con, $get_cats);
while ($row_cats=mysqli_fetch_array($run_cats)){
    $cat_id = $row_cats['cat_id'];
    $cat_name = $row_cats['name'];
echo "<li><button><a href='index.php?cat=$cat_id'>$cat_name</a></button></li>";
}
}

It's possible to use form action= in this case?

Aniket Sahrawat
  • 12,410
  • 3
  • 41
  • 67
  • @devpro : Thats not working because of tag – Rakesh Sojitra Nov 08 '16 at 07:46
  • why u need select box here? u can choose one select or ul li – devpro Nov 08 '16 at 07:50