RoseG Posted February 1, 2012 Share Posted February 1, 2012 I am trying to redirect users depending on their coupon code input I am using the following script in the form created in dreamweaver: <form action="CodeUserredirect.php" method="post" enctype="multipart/form-data" name="" id=""> <input type="hidden" name="redirect" value="CodeUserredirect.php" /> <p class="style4">Redeem your Gift Certificate Savings for Special Orders here:</p> <p><span class="style78">Enter Coupon code</span> <input name="CouponCode" type="text" id="CouponCode" size="9"> <input type="submit" name="CheckCode" id="CheckCode" value="Check Code"> <br/> <br/> </p> </form> and I am using the following code in my php file: <?php $coupon_code = $_POST['couponcodenumber']; if ($coupon_code = $some_other_value) { $redirected_address = 'Location: specialordersDiscountForm.php'; header ($redirected_address); exit(); } else { $redirected_address = 'Location: specialorderwrongcode.php'; header ($redirected_address); exit(); } ?> Not sure where the issue is in these coding but it is not working to redirect users depending on their coupon input as intended. Can anyone supply me with a working code or explain what the issue is? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/256190-trying-to-figure-this-code-out/ Share on other sites More sharing options...
spiderwell Posted February 1, 2012 Share Posted February 1, 2012 the if statement has only 1 = sign thats probably where its falling over. Quote Link to comment https://forums.phpfreaks.com/topic/256190-trying-to-figure-this-code-out/#findComment-1313343 Share on other sites More sharing options...
RoseG Posted February 1, 2012 Author Share Posted February 1, 2012 the if statement has only 1 = sign thats probably where its falling over. Thanks Spiderwell, but when I add two ='s it only takes me to the last redirected page no matter what the user enters, I will like it to go to one page if they enter the correct coupon code or the other if entered wrong. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/256190-trying-to-figure-this-code-out/#findComment-1313348 Share on other sites More sharing options...
spiderwell Posted February 1, 2012 Share Posted February 1, 2012 have you put a value into the $some_other_value variable? <?php $coupon_code = $_POST['couponcodenumber']; if ($coupon_code == $some_other_value) { header ('Location: specialordersDiscountForm.php'); exit(); } else { header ('Location: specialorderwrongcode.php'); exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/256190-trying-to-figure-this-code-out/#findComment-1313350 Share on other sites More sharing options...
RoseG Posted February 1, 2012 Author Share Posted February 1, 2012 have you put a value into the $some_other_value variable? <?php $coupon_code = $_POST['couponcodenumber']; if ($coupon_code == $some_other_value) { header ('Location: specialordersDiscountForm.php'); exit(); } else { header ('Location: specialorderwrongcode.php'); exit(); } ?> If I put the coupon code number there as well it still takes users to the page they should be at when they get the code wrong. it takes them there whether the code they enter is correct or not. Quote Link to comment https://forums.phpfreaks.com/topic/256190-trying-to-figure-this-code-out/#findComment-1313367 Share on other sites More sharing options...
spiderwell Posted February 1, 2012 Share Posted February 1, 2012 as i said, what have you given the value of the variable $some_other_value? does it match the input from the POST['couponcodenumber'] Quote Link to comment https://forums.phpfreaks.com/topic/256190-trying-to-figure-this-code-out/#findComment-1313452 Share on other sites More sharing options...
AyKay47 Posted February 1, 2012 Share Posted February 1, 2012 from the given form, I do not see an input value with name='couponcodenumber', which means $_POST['couponcodenumber'] will never exist, and never equal $some_other_value (we have no clue where $some_other_value is coming from either). That being said, the correct $_POST index, according to your code, should be $_POST['CouponCode']: $coupon_code = $_POST['CouponCode']; if ($coupon_code == $some_other_value) { header ("Location: specialordersDiscountForm.php"); exit(); } else { header ("Location: specialorderwrongcode.php"); exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/256190-trying-to-figure-this-code-out/#findComment-1313474 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.