stallonmabro Posted August 29, 2015 Share Posted August 29, 2015 Pls, how can i get this php code to redirect to the first header location url whenever the user input matches anyone of the numbers in the $tracking = array, and redirects to the second header location whenever the user input doesnt match any of the numbers in the $tracking = array. <?php $tracking = $_post['tracking']; //your form method is post $tracking = array('91911', '91914', '91915', '91932', '91942', '91945', '91950', '92014', '92025', '92027', '92029', '92037', '92064', '92065', '92067', '92071', '92075', '92101', '92102', '92103', '92104', '92105', '92106', '92107', '92108', '92109', '92110', '92111', '92113', '92114', '92115', '92116', '92117', '92118', '92119', '92120', '92121', '92122', '92123', '92124', '92126', '92127', '92128', '92129', '92130', '92131', '92132', '92134', '92135', '92139', '92140', '92145', '92147', '92154', '92173'); if (in_array($tracking, $tracking)){ header("Location: http://queensdeliverys.com/".$_post['selection']); exit; } else { header("Location: http://www.pureflo.com"); exit; } this is the html form action and method details. <form action="/QDS-tracking/validate.php" id="search-form" method="get" name="tracking"><input class="s-f-input search" id="order_number" name="TrackingModel[order_number]" placeholder="Enter your Order Number" tabindex="1" type="text" /><input class="search-btn" name="yt0" type="submit" value="Track" /></form> ?> any help will be greatly appreciated, thanks this is the link you can test the code on. queensdeliverys.com/QDS-tracking/tracking.html and it should redirect to http://queensdeliverys.com if the code is fixed, and http://www.pureflo.com if it isnt fix yet. thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/297978-pls-i-need-help-with-my-codehelp/ Share on other sites More sharing options...
Barand Posted August 29, 2015 Share Posted August 29, 2015 try using different variable names for the input and the array. Quote Link to comment https://forums.phpfreaks.com/topic/297978-pls-i-need-help-with-my-codehelp/#findComment-1519891 Share on other sites More sharing options...
ginerjm Posted August 29, 2015 Share Posted August 29, 2015 Where to start? 1 - post code in the forum properly using the tags as described in the rules. 2 - Learn at least a LITTLE bit about php - specifically that it is case-sensitive. That means that $_post['tracking'] is invalid. 3 - Turn on php error checking in all your scripts during development so that things like #2 show up as the errors that they are. 4 - When writing code put statements on separate lines. Makes reading them much easier as well as editing later on. Yes - do as Barand suggested but also do try to do some of the things that I just posted before you post more code here. It will greatly help your cause. Quote Link to comment https://forums.phpfreaks.com/topic/297978-pls-i-need-help-with-my-codehelp/#findComment-1519893 Share on other sites More sharing options...
Barand Posted August 29, 2015 Share Posted August 29, 2015 Also note that you do not have an input in your form with the name "tracking", so $_POST['tracking'] will not exist. Quote Link to comment https://forums.phpfreaks.com/topic/297978-pls-i-need-help-with-my-codehelp/#findComment-1519896 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.