When pressing 'back' button after search form submit, page won't load

Hi guys, this might be tricky to explain but here goes.

I have my main index.php “www.website.com” that has a link to “www.website.com/products/

When you go to the products section, I have a search form included on the page. Everything in the initial form is selected/populated by default ( crude description: if !isset POST, $company_names = all, and $color = all) and products listed based on those defaults.

This is the code for the search form.

<form action="index.php" method="post">
	<select name="company_names" id="company_names">
		<option name="company" value="all">All</option>
                <option name="company" value="company1">Company1</option>
                <option name="company" value="company2">Company2</option>
                etc etc.
        <select name="color" id="color">
		<option value="all">All</option>
		<option value="black">Black</option>
		<option value="red">Red</option>
                etc etc.

<input type="submit" name="sort_submit" value="Search"/>

The form works perfectly for its intended purpose. However, once I search for different search parameters… yes, it works, but if I press ‘back’ on the browser, the page doesn’t load (I know why, because it doesn’t remember the default parameters…) - and that is the problem I am confused about.

Am I doing something wrong in my form setup? Or what?

If more code is required I can post some. Hopefully that made sense to someone.

Thanks for any help with this.

edit: woops. posted in the wrong section! I only just realized it has hardly anything to do with the php side of my page, at least from what I know. my bad.

edit 2: after some reading, maybe I am supposed to be using GET instead of POST in my form?

So I’m attempting to switch to method=“GET” in my form, but running into issues (the php code I had to make the search work now doesn’t at all)

what I had was this:

if (isset($_POST['submit']) && (!isset($_GET['id']))) {
	$company_names = mysqli_real_escape_string($link, $_POST['company_names']);
	$color = mysqli_real_escape_string($link, $_POST['color']);
output the result

This worked fine with my method=“POST” form, but switching it to method=“get” it doesn’t work at all.

The correct GET attributes from my search form are being put in the URL, however. so the search is working…but I’m not handling it with php correctly, apparently…

I tried switching $_POST[‘company_names’] and $_POST[‘color’] to $_GETs, that didn’t work either. my search results are not changing. even though the url is being updated with the search options I choose…

Anyone got any ideas?

solved for now, changed them all to $_GETs, but also had another $_POST further down that I had to change…works now.