Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,261 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,176 people online right now. Registration is fast and FREE... Join Now!




if statement help plz :)

 
Reply to this topicStart new topic

if statement help plz :), Using if statement with form values

Mike88
12 Oct, 2008 - 01:16 AM
Post #1

New D.I.C Head
*

Joined: 12 Oct, 2008
Posts: 3

Hey all I am pretty much new to php and I am trying to use an if statement thing to assign a variable. Using the if statement I want to grab data from another variable which is getting its data from a html select form. Basically I want to pull two different things from the select form that are related to the one thing if you get that lol. So my code is like this (simplified):

CODE

<select name="program">
<option value="100-100">Result1</option>
<option value="100-200">Result2</option>

<?php

$program = $_POST['program'];

if ($program==100-100) $result = headache;
if ($program==100-200) $result = biggerheadache;

?>


I am getting an error: Parse error: syntax error, unexpected T_IF

I am not to sure if I am writing the if statement correctly or if this is actually the easiest way to go about doing what I want to do, any help much appreciated biggrin.gif

This post has been edited by Mike88: 12 Oct, 2008 - 02:27 AM
User is offlineProfile CardPM
+Quote Post

Mike88
RE: If Statement Help Plz :)
12 Oct, 2008 - 02:30 AM
Post #2

New D.I.C Head
*

Joined: 12 Oct, 2008
Posts: 3

Well I fixed it! just had to add ' before and after my numbers in the if statement lol oh and add the bracket thingys tongue.gif

FROM THIS:
CODE
<?php

$program = $_POST['program'];

if ($program==100-100) $result = headache;
if ($program==100-200) $result = biggerheadache;

?>


TO THIS:
CODE
<?php

$program = $_POST['program'];

if ($program=='100-100') {$result = headache;}
if ($program=='100-200') {$result = biggerheadache;}

?>

User is offlineProfile CardPM
+Quote Post

Moonbat
RE: If Statement Help Plz :)
12 Oct, 2008 - 07:45 AM
Post #3

D.I.C Regular
Group Icon

Joined: 30 Jun, 2008
Posts: 391



Thanked: 22 times
Dream Kudos: 600
My Contributions
I'm assuming you already have a submit button somewhere to submit the form value.

This code is probably where the error is:

CODE
if ($program==100-100) $result = headache;
if ($program==100-200) $result = biggerheadache;


I would put the comparisons in quotes and I would put the code to be executed for each statement in braces, like this:

CODE
if ($program == "100-100") { $result = headache; }
if ($program == "100-200") { $result = biggerheadache; }


See if that works.


User is offlineProfile CardPM
+Quote Post

Hary
RE: If Statement Help Plz :)
12 Oct, 2008 - 08:17 AM
Post #4

D.I.C Head
**

Joined: 23 Sep, 2008
Posts: 205



Thanked: 15 times
My Contributions
I do not want to ruin your day, but he did post the answer himself earlier wink2.gif
User is offlineProfile CardPM
+Quote Post

Moonbat
RE: If Statement Help Plz :)
12 Oct, 2008 - 09:14 AM
Post #5

D.I.C Regular
Group Icon

Joined: 30 Jun, 2008
Posts: 391



Thanked: 22 times
Dream Kudos: 600
My Contributions
QUOTE(Hary @ 12 Oct, 2008 - 09:17 AM) *

I do not want to ruin your day, but he did post the answer himself earlier wink2.gif

Oh crap, I didn't even notice that! crazy.gif

Thanks for pointing that out Hary. I gotta stop coming here the minute I get up from bed...
User is offlineProfile CardPM
+Quote Post

umesh.daiya@isol.co.in
RE: If Statement Help Plz :)
15 Oct, 2008 - 06:32 AM
Post #6

New D.I.C Head
*

Joined: 15 Oct, 2008
Posts: 5

QUOTE(Mike88 @ 12 Oct, 2008 - 02:16 AM) *

Hey all I am pretty much new to php and I am trying to use an if statement thing to assign a variable. Using the if statement I want to grab data from another variable which is getting its data from a html select form. Basically I want to pull two different things from the select form that are related to the one thing if you get that lol. So my code is like this (simplified):

CODE

<select name="program">
<option value="100-100">Result1</option>
<option value="100-200">Result2</option>

<?php

$program = $_POST['program'];

if ($program==100-100) $result = headache;
if ($program==100-200) $result = biggerheadache;

?>


I am getting an error: Parse error: syntax error, unexpected T_IF

I am not to sure if I am writing the if statement correctly or if this is actually the easiest way to go about doing what I want to do, any help much appreciated biggrin.gif


i think u should use this
if($program=="100-100") $result="headache";
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 04:37AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month