Redirect not functioning

I have a page menukaart_listing.php on which you arive after you have choosen a category from a dropdown list using post .


	<form class="select_form" action="menukaart_listing.php" method="post">
	  <label>Menu Categorie:</label> 
	  <select name="menu_id" class="selectfield">
	    <option value="">Select Categorie</option>
		<?php 
	      $categories = mysql_query("SELECT menu_kaart_id, menu_kaart_sequence, menu_kaart_type_nl 
		                            FROM menu_kaart
									ORDER BY menu_kaart_sequence") or die(mysql_error());
									
		  while ($row = mysql_fetch_assoc($categories)) {						
		    echo "<option value=\\"{$row['menu_kaart_id']}\\">{$row['menu_kaart_type_nl']}</option>";
		  }
	    ?>
	  </select>
	  <p><input type="submit" name="submit" value="Submit" class="button" /></p>
	</form>

After each menu item on the listing page I have an anchor called edit:

<a href="edit_menukaart_item.php?item_id={$row['menu_kaart_item_id']}">wijzig</a>

which as you can see brinks you to a edit page (edit_menukaart_item.php) After an edit/update is done and the form is submitted I would like to go back to the listing page showing the same category as before! So I added a hidden field to the edit/update form called menu_id:

<input type="hidden" name="menu_id" value="<?php echo $row->menu_kaart_id;?>" />

And I am using the following redirect:

header('Location: '.DIRADMIN.'menukaart_listing.php?menu_id='.$menu_id);

It redirects to menukaart_listing.php and it sends the query string as well as I can see in the url, but it doesn’t show me the listing. What am I doing wrong?

Thank you in advance

I think the problem is due to the way you set the variable $menu_id, in that you are normally using POST to get value in the first place then sending with GET on the redirect. Something like this should cover both, defaulting to zero (which should result to no record found).


//Default to zero so we don't pass empty value to query.
$menu_id = (isset($_POST['menu_id']) ? $_POST['menu_id'] : '0');
$menu_id = (isset($_GET['menu_id']) ? $_GET['menu_id'] : $menu_id);

Goodmorning Drummin. Thank you for the reply. Let me refrase your answer. So instead of having just:

$menu_id  = $_POST['menu_id'];

in the edit page. I should use:


$menu_id = (isset($_POST['menu_id']) ? $_POST['menu_id'] : '0'); 
$menu_id = (isset($_GET['menu_id']) ? $_GET['menu_id'] : $menu_id);

Is that right? Thank you

Hi Drummin. Works as a charm :tup: Thanks