Jump to content

If then statement not passing variables


anthonydamasco

Recommended Posts

I seem to be having trouble throwing a var into a database

$branchemail is the var not being pushed
i 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!
Link to comment
Share on other sites

Change your if to a switch()

[code]
<?php

switch($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
Link to comment
Share on other sites

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]<?php
switch(strtolower($nearestlocation)) {
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.