PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
imimin
Forum Commoner
Posts: 38 Joined: Thu Oct 18, 2007 5:44 pm
Post
by imimin » Sun May 10, 2009 9:00 pm
Cansomeone help me out here?
I am trying to set up a _GET command and echo a variable in an OPTION statement in a dropdown list. What I have so far is this (line 3 is my challenge) , but it doesn't work:
Code: Select all
Garment Style:
<SELECT NAME=custom10 SIZE=1>
<OPTION SELECTED="SELECTED" VALUE=<?php $item_prod_name = $_GET['item_prod_name']; echo "$item_prod_name">echo "$item_prod_name"</OPTION>?>
<OPTION VALUE="Goucho Pants w/Elastic Waist">Goucho Pants w/Elastic Waist</OPTION>
<OPTION VALUE="Goucho Pants w/Draw String">Goucho Pants w/Draw String</OPTION>
<OPTION VALUE="Poncho w/Hood">Poncho w/Hood</OPTION>
<OPTION VALUE="Poncho without Hood">Poncho without Hood</OPTION>
<OPTION VALUE="Baby Bunting">Baby Bunting</OPTION>
<OPTION VALUE="Romper">Romper</OPTION>
</SELECT><BR>
Any help on this would be appreciated.
Last edited by
Benjamin on Sun May 10, 2009 9:41 pm, edited 2 times in total.
Reason: Changed code type from text to html.
imimin
Forum Commoner
Posts: 38 Joined: Thu Oct 18, 2007 5:44 pm
Post
by imimin » Sun May 10, 2009 9:19 pm
I also tried this:
Code: Select all
<?php
$item_prod_name = $_GET['item_prod_name'];
Garment Style:
<SELECT NAME=custom10 SIZE=1>
<OPTION SELECTED="SELECTED" VALUE=echo "$item_prod_name">echo "$item_prod_name"</OPTION>
<OPTION VALUE="Goucho Pants w/Elastic Waist">Goucho Pants w/Elastic Waist</OPTION>
<OPTION VALUE="Goucho Pants w/Draw String">Goucho Pants w/Draw String</OPTION>
<OPTION VALUE="Poncho w/Hood">Poncho w/Hood</OPTION>
<OPTION VALUE="Poncho without Hood">Poncho without Hood</OPTION>
<OPTION VALUE="Baby Bunting">Baby Bunting</OPTION>
<OPTION VALUE="Romper">Romper</OPTION>
</SELECT><BR>
?>
and it DIDN'T WORK and got this error:
Parse error: syntax error, unexpected T_STRING in /file/poj/poj_order_form.php on line 65
Thank you!
Last edited by
Benjamin on Sun May 10, 2009 9:41 pm, edited 1 time in total.
Reason: Changed code type from text to html.
mickd
Forum Contributor
Posts: 397 Joined: Tue Jun 21, 2005 9:05 am
Location: Australia
Post
by mickd » Sun May 10, 2009 10:30 pm
Any HTML has to be echo'ed out from the PHP. You can't have this:
Code: Select all
<?php
$foo = 'Hello!';
<div>
echo $foo;
</div>
?>
But you can have this:
Code: Select all
<?php
$foo = 'Hello!';
echo '<div>';
echo $foo;
echo '</div>';
// or
echo '<div>'.$foo.'</div>';
// or
?>
<div><?php echo $foo; ?></div>
Hope that helps.
imimin
Forum Commoner
Posts: 38 Joined: Thu Oct 18, 2007 5:44 pm
Post
by imimin » Mon May 11, 2009 11:09 am
OK then, when I try this:
Code: Select all
<?php
$item_selected_style = $_GET['item_selected_style'];
echo "Garment Style:";
<SELECT NAME=custom10 SIZE=1>;
echo
"<OPTION SELECTED="SELECTED" VALUE="$item_selected_style">"$item_selected_style"</OPTION>
<OPTION VALUE="Goucho Pants w/Elastic Waist">Goucho Pants w/Elastic Waist</OPTION>
<OPTION VALUE="Goucho Pants w/Draw String">Goucho Pants w/Draw String</OPTION>
<OPTION VALUE="Poncho w/Hood">Poncho w/Hood</OPTION>
<OPTION VALUE="Poncho without Hood">Poncho without Hood</OPTION>
<OPTION VALUE="Baby Bunting">Baby Bunting</OPTION>
<OPTION VALUE="Romper">Romper</OPTION>";
</SELECT><BR>;
?>
it is still NOT working. I get the following error:
Parse error: syntax error, unexpected '<' in /homepages/27/d120150310/htdocs/poj/poj_order_form.php on line 69
Thank you!
Last edited by
Benjamin on Mon May 11, 2009 11:18 am, edited 1 time in total.
Reason: Changed code type from text to php.
mdk999
Forum Newbie
Posts: 22 Joined: Fri May 08, 2009 3:21 pm
Post
by mdk999 » Mon May 11, 2009 1:25 pm
your issue is that you have not escaped the quotes within the echo statement. You can get around this by using a multi-line string ..
Code: Select all
<?php
$item_selected_style = $_GET['item_selected_style'];
$select = <<<FO
Garment Style:
<SELECT NAME=custom10 SIZE=1>
<OPTION SELECTED="SELECTED" VALUE="{$item_selected_style}">"{$item_selected_style}"</OPTION>
<OPTION VALUE="Goucho Pants w/Elastic Waist">Goucho Pants w/Elastic Waist</OPTION>
<OPTION VALUE="Goucho Pants w/Draw String">Goucho Pants w/Draw String</OPTION>
<OPTION VALUE="Poncho w/Hood">Poncho w/Hood</OPTION>
<OPTION VALUE="Poncho without Hood">Poncho without Hood</OPTION>
<OPTION VALUE="Baby Bunting">Baby Bunting</OPTION>
<OPTION VALUE="Romper">Romper</OPTION>
</SELECT><BR>
FO;
echo $select;
?>
Last edited by
Benjamin on Mon May 11, 2009 1:33 pm, edited 1 time in total.
Reason: Changed code type from text to php.