0

I have a simple form made in PHP, I am trying to pass the select value in the page mentioned in the action URL,

<form action="filtertable.php" method="post">
    <select class="form-select" name="filtercategory" aria-label="Default select example"
        onchange="this.form.submit()">
        <option selected>Select Category</option>
        <option value="<?php echo $roww["c_id"]; ?>"><?php echo $roww["cname"]; ?></option>
    </select>
</form>

when the user selects on any select box it will go to the page filtertable.php, and from there am trying to get the selected value like this:

<?php

$filtercategory=$_POST['filtercategory'];

However it doesn't work, can anyone please tell me what is wrong in here, thanks in advance

amlxv
  • 1,610
  • 1
  • 11
  • 18
love lio
  • 147
  • 8
  • 1
    From what I can see and test, this should work. There might be something else in your code, which is not in your question, causing this problem. – KIKO Software Mar 04 '22 at 07:33
  • @KIKOSoftware this is only the code, just some select statment and while loop to get the values from database i trimmed to make it simple here – love lio Mar 04 '22 at 07:36
  • What actually doesn't work? Is the page not changing? Or the `$_POST['filtercategory']` is empty? – amlxv Mar 04 '22 at 07:38
  • the page is being taken to filtertable.php correctly, but from there am not getting $_POST['filtercategory'], its empty – love lio Mar 04 '22 at 07:41
  • Did you already put them in ` – amlxv Mar 04 '22 at 07:42
  • @You yes , https://jsfiddle.net/x4a1bmw0/1/ this is my filtertable.php code – love lio Mar 04 '22 at 07:44
  • That's a lot of code. Anyway, the first thing I would do is check the [console panel](https://developer.mozilla.org/en-US/docs/Tools/Browser_Console) for any error message. – KIKO Software Mar 04 '22 at 07:48
  • Then check in the developer tools whether `$_POST` is indeed empty as you say. I doubt it is. And then I would add [PHP error reporting](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display), if you haven't already. Basically the standard debugging steps you would take in a situation like this. – KIKO Software Mar 04 '22 at 07:55
  • From the linked code: When the page loads `$filtercategory=$_POST['filtercategory'];` this will cause an error as the page will be loaded using GET ( line #37) – Professor Abronsius Mar 04 '22 at 07:58
  • @ProfessorAbronsius i didnt really understand – love lio Mar 04 '22 at 08:12
  • You have your code that _shows_ the form, and the code that is supposed to process the submitted data, in the same file here. When you first navigate to this script, either by putting the link into your browser address bar, or by clicking a link that leads to it - that will cause a _GET_ request. No form has been submitted at this point, no POST data will exist. Yet you are trying to access `$_POST['filtercategory']` anyway; of course it will be empty at this point. – CBroe Mar 04 '22 at 09:46

0 Answers0