Jump to content

Recommended Posts

Ok, i am adding a few things onto a "php email form" script, everything works as it should apart from this.

 

The php email form, catches the submitted data and emails it accordingly, then after that, i use some of the data and show it, one form value i would like to show is from a radio button. Theres two radio buttons in one group.

 

The radio buttons group name is "postage", value1 = "first" value2 = "second".

 

$post1 is one cost, and $post2 is another cost, both get submitted an received fine.

 

And as it stands when i submit the form without the line below, and tell it to echo "postage", it works fine. IF though i add this line after:

 

if ($postage = "first") {$post_cost = $post1;} elseif ($postage = "second") {$post_cost = $post2;}

If simply just comes threw as "first" everytime regardless, Why??

Heres the code for this section:

//Collect postage details
if(isset($_REQUEST['postage'])){$postage = stripslashes($_REQUEST['postage']);}
if(isset($_REQUEST['post1']) && !empty($_REQUEST['post1'])){$post1 = stripslashes($_REQUEST['post1']);}
if(isset($_REQUEST['post2']) && !empty($_REQUEST['post2'])){$post2 = stripslashes($_REQUEST['post2']);}
if(isset($_REQUEST['Total:']) && !empty($_REQUEST['Total:'])){$total = stripslashes($_REQUEST['Total:']);}

//Get disired postage type
$post_cost = 0;
if ($postage = "first") {$post_cost = $post1;} elseif ($postage = "second") {$post_cost = $post2;}

//Work out total to pay
$totaltopay = $total+$post_cost;
?> 

Thanks

Andy

 

 

 

Still not sure why the if statement wasnt working.

Because you was using the assignment operator ( = ) rather than the comparison operator ( == ).

Assignment operator is used to assign something a value

Comparison operator is used to compare values.

if ($postage = "first") {$post_cost = $post1;} elseif ($postage = "second") {$post_cost = $post2;}

 

You could of wrote the above using a ternary opertor ( ?: )

$post_code = ($postage == "first" ? $post1 : $post2)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.