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 ="karen.hartzel@accustaffing.com"; $branchphone ="856-482-2222"; } elseif ($nearestlocation =='pennsauken'){ $branchemail ="pennsauken.office@accustaffing.com"; $branchphone ="856-662-2727"; } elseif($nearestlocation =='burlington'){ $branchemail ="burlington.office@accustaffing.com"; $branchphone ="609-387-2900"; } elseif($nearestlocation =='woodburyheights'){ $branchemail ="woodbury.office@accustaffing.com"; $branchphone ="856-845-3900"; } elseif($nearestlocation =='atlanticcity'){ $branchemail ="ac.office@accustaffing.com"; $branchphone ="609-344-1300"; } elseif($nearestlocation =='philadelphia'){ $branchemail ="philadelphia.office@accustaffing.com"; $branchphone ="215-568-2228"; } elseif($nearestlocation =='vineland'){ $branchemail ="vineland.office@accustaffing.com"; $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! Quote Link to comment 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 ="karen.hartzel@accustaffing.com"; $branchphone ="856-482-2222"; break; case 'pennsauken': $branchemail ="pennsauken.office@accustaffing.com"; $branchphone ="856-662-2727" break; case 'burlington': $branchemail ="burlington.office@accustaffing.com"; $branchphone ="609-387-2900"; break; case 'woodburyheights': $branchemail ="woodbury.office@accustaffing.com"; $branchphone ="856-845-3900"; break; case 'atlanticcity' : $branchemail ="ac.office@accustaffing.com"; $branchphone ="609-344-1300"; break; case 'philadelphia': $branchemail ="philadelphia.office@accustaffing.com"; $branchphone ="215-568-2228"; break; case 'vineland': $branchemail ="vineland.office@accustaffing.com"; $branchphone ="856-794-8282"; break;}?>[/code]See if that helps Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
anthonydamasco Posted December 14, 2006 Author Share Posted December 14, 2006 no it didnt work Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.