anthonydamasco Posted December 14, 2006 Share Posted December 14, 2006 I seem to be having trouble throwing a var into a database$branchemail is the var not being pushedi have an if/then statement[code=php:0]if($nearestlocation =='cherryhill'){ $branchemail ="[email protected]"; $branchphone ="856-482-2222"; } elseif ($nearestlocation =='pennsauken'){ $branchemail ="[email protected]"; $branchphone ="856-662-2727"; } elseif($nearestlocation =='burlington'){ $branchemail ="[email protected]"; $branchphone ="609-387-2900"; } elseif($nearestlocation =='woodburyheights'){ $branchemail ="[email protected]"; $branchphone ="856-845-3900"; } elseif($nearestlocation =='atlanticcity'){ $branchemail ="[email protected]"; $branchphone ="609-344-1300"; } elseif($nearestlocation =='philadelphia'){ $branchemail ="[email protected]"; $branchphone ="215-568-2228"; } elseif($nearestlocation =='vineland'){ $branchemail ="[email protected]"; $branchphone ="856-794-8282"; }[/code]and then i have my query[code=php:0]$sql = "INSERT INTO jobsearch VALUES (NULL, '$positiontitle', '$city', '$hourlyrate', '$workinghours', '$positiondescription', '$positiontype', '$nearestlocation', '$timeneeded', '$positionclassification', SYSDATE(), '$expire', '$branchemail', '$branchphone')";mysql_query($sql) or die ( "Problem with the query: $sql<br>" . mysql_error() );}[/code]everything but $branchemail goes to my database! any ideas, Ive looked at this script for ever, I just dont see it! Link to comment https://forums.phpfreaks.com/topic/30668-if-then-statement-not-passing-variables/ Share on other sites More sharing options...
SharkBait Posted December 14, 2006 Share Posted December 14, 2006 Change your if to a switch()[code]<?phpswitch($nearestlocation) { case 'cherryhill': $branchemail ="[email protected]"; $branchphone ="856-482-2222"; break; case 'pennsauken': $branchemail ="[email protected]"; $branchphone ="856-662-2727" break; case 'burlington': $branchemail ="[email protected]"; $branchphone ="609-387-2900"; break; case 'woodburyheights': $branchemail ="[email protected]"; $branchphone ="856-845-3900"; break; case 'atlanticcity' : $branchemail ="[email protected]"; $branchphone ="609-344-1300"; break; case 'philadelphia': $branchemail ="[email protected]"; $branchphone ="215-568-2228"; break; case 'vineland': $branchemail ="[email protected]"; $branchphone ="856-794-8282"; break;}?>[/code]See if that helps Link to comment https://forums.phpfreaks.com/topic/30668-if-then-statement-not-passing-variables/#findComment-141313 Share on other sites More sharing options...
anthonydamasco Posted December 14, 2006 Author Share Posted December 14, 2006 ill try it, whats the differance? between if/then and switch? Link to comment https://forums.phpfreaks.com/topic/30668-if-then-statement-not-passing-variables/#findComment-141316 Share on other sites More sharing options...
anthonydamasco Posted December 14, 2006 Author Share Posted December 14, 2006 no it didnt work Link to comment https://forums.phpfreaks.com/topic/30668-if-then-statement-not-passing-variables/#findComment-141318 Share on other sites More sharing options...
Psycho Posted December 14, 2006 Share Posted December 14, 2006 A switch is designed to specify different actions based upon a particular value - exactly what you have. Doing a multiple of "if else" statements is inefficient.You need to verify that $nearestlocation is what you are testing for. Are you sure that the case of the letters in your test is the same as in the value of $nearestlocation?"philadelphia" != "Philadelphia"It's probably a good idea to change the switch statement to this:[code]<?phpswitch(strtolower($nearestlocation)) {?>[/code] Link to comment https://forums.phpfreaks.com/topic/30668-if-then-statement-not-passing-variables/#findComment-141325 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.