Jump to content

trying to figure this code out


RoseG

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/256190-trying-to-figure-this-code-out/
Share on other sites

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!

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();
}
?> 

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.

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();
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.