gibbon25 Posted September 9, 2010 Share Posted September 9, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/212949-one-line-if-statement-causing-me-big-issues/ Share on other sites More sharing options...
gibbon25 Posted September 9, 2010 Author Share Posted September 9, 2010 Ok, i have done it using a case statement. Still not sure why the if statement wasnt working. Andy Quote Link to comment https://forums.phpfreaks.com/topic/212949-one-line-if-statement-causing-me-big-issues/#findComment-1109098 Share on other sites More sharing options...
wildteen88 Posted September 9, 2010 Share Posted September 9, 2010 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) Quote Link to comment https://forums.phpfreaks.com/topic/212949-one-line-if-statement-causing-me-big-issues/#findComment-1109114 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.