KillerWolf Posted November 27, 2006 Share Posted November 27, 2006 ok what ive been trying to do is allow a user to pick an upgrade parrt and then out put using an switching statment the awnser to what he or she should upgrade to. this is what i have, but i still stuck on finding out why it does not out print into my text are with the appropriate echo statement. any help would be greatly appreciated.thxWolf[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Modders Back Door</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><style type="text/css"><!--@import url("style2.css");--></style></head><body> <?php$choices[]="please choose a part";$choices[]="cpu";$choices[]="sound card";$choices[]="video card";$choices[]="hard drive";$chooser = $_POST['choices'];$req_chooser="Area of interest";if ($_POST['Submit']) { if($_POST['chooser']==$choices[0]&&$req_chooser){ $missing[]=$req_chooser; } if(count($missing)>0){ print "<h1>Missing your choice</h1>"; $s=""; if(count($missing)>1){ $s="s"; } print "<div class=\"indent10\">You missed out the following required field$s:<br><ul>\n"; for ($i=0; $i<count($missing); $i++){ print "<li>$missing[$i]</li>"; } print"</ul></div>"; // exit; }//endifcountmissing}?><form action="<?php $_SERVER['PHP_SELF']?>" method="post"><h3>choose a part</h1><fieldset> <span class="headermain"> <b>choice</b> <?php if(!$_POST['chooser']){ $a[0]=" selected"; } print"<select name=\"chooser\">\n"; for($i=0; $i<count($choices); $i++){ if($_POST['chooser']==$choices[$i]){ $a[$i]=" selected"; $i = $chooser; //if($i = cpu ) { //echo "$part"; //} } print "<option$a[$i]>$choices[$i]</option>\n"; } ?><textarea name="chooser" rows="3" cols="20"> <?php$part = choices;switch ($part){ case "cpu": echo "core 2 duo for $500"; break; case "video": echo "Wait for a card that is direct3D 10"; break; case "harddrive": echo "how much is to much"; break; case "ram": echo "You should use DDR2"; break; case "sound": echo "The soundblaster zs2 is the best buy."; break; echo "Your Part: " . $part . " \n"; }?> </textarea></p><input type="submit" name="submit" value="submit" /> </feildset></form></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/28674-switching-statments/ Share on other sites More sharing options...
kenrbnsn Posted November 27, 2006 Share Posted November 27, 2006 You forgot the "$" on the variable $choices here:[code]<?php$part = choices;?>[/code]But since $choices is an array, that won't work either. You may need a foreach here instead.Ken Link to comment https://forums.phpfreaks.com/topic/28674-switching-statments/#findComment-131216 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.