Forum Moderators: coopster

Message Too Old, No Replies

Using If-Then and Addition to modify a form's output

Modfying variables based on user imput

         

lindseylicious

8:28 pm on Jan 31, 2007 (gmt 0)

10+ Year Member



I have a form selling a product that allows the users to select up to three different options (input type is checkbox) to modify the product. Each of the options will add an additional $5.00 to the base price of the product (which has a hidden input).

I've been trying to use if-then statements like this:

if ($option1 == "yes")
{$price += 5}

Anyway, it's not working AT ALL and causing the entire php file to stop functioning. ANY help at all would be so greatly appreciated... especially help on applying this if-then to all three options.. Thanks so much!

justageek

8:38 pm on Jan 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming all your variables are correct then this should work just fine:

if($option1 == "yes"){
$price += 5;
}

JAG

lindseylicious

8:55 pm on Jan 31, 2007 (gmt 0)

10+ Year Member



Hmm.. I must have screwed something else up then, because it's still not working.
Here are the relevant parts from the HTML:

<input type="hidden" name="price" value="55.00">

Optional Features:<br />
Gold Clasps:<input name="gclasps" type="checkbox" class="oform" value="yes" /><br />
Silver Clasps:<input name="sclasps" type="checkbox" class="oform" value="yes" />

And here is the relevant PHP:

$price=$_POST['price'];
$gold_clasps = $_POST['gclasps'];
$silver_clasps = $_POST['sclasps'];

if($gclasps == "yes"){
$price =+ 5.00
}

Huge mistakes?

justageek

8:57 pm on Jan 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Semi colon missing :-/

if($gclasps == "yes"){
$price += 5.00;
}

JAG

lindseylicious

9:02 pm on Jan 31, 2007 (gmt 0)

10+ Year Member



Oops!
Hah thank you so much, JAG. You saved the day!

justageek

9:17 pm on Jan 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Love those easy fixes :-)

JAG