Undefined Variable – Do Switch Statements have scope in PHP

Hello to all this is my first time posting, thought it would be good since im utterly stuck. It was my understanding that switch and If/else statements in PHP do not have variable scope.

My issue is I have a CSV file ( a sample one) with about 5 rows of values and I need to get it put into a mySQL DB table( the column headers are represented in my “cases” for my switch statement) BUt anyways I’m parsing the CSV file and checking to make sure that the data is in the column it should be and storing it in a variable. I am then storing all of the variables in an array that is getting serialized and then getting passed into a my SQL query.

I continue to get the error
SCREAM: Error suppression ignored for
( ! ) Notice: Undefined variable: company in C:\wamp\www\lcimport\serialize.php on line 98

But I know those variables are there cause I can echo them and they will be called. But unless those errors go away my query will not run thus not populating my db table.

what am I doing wrong?

   <?php
//define some constants
$db = 'lc';
mysql_connect('localhost', 'root', ''); 
mysql_select_db($db);
 mysql_error();
$uid = md5(uniqid(time()));

//we only have this here to be a row counter
$row = 1;
if (($handle = fopen("C:\\wamp\\www\\lcimport\\4records.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        //var_dump($data);
       // echo $data[0];
        echo '';
        if ($row === 1) {
        $header = $data;
       }     

        $row++;
        for ($c=0; $c < $num; $c++) {
            //echo $data[$c] . "<br />\n";
            if ($row === 2) continue;
             switch ($header[$c] ){
              case "Contact":
                      $contact = explode (" ", $data[$c]);
                      $firstName =  $contact[0];
                      $lastName =  $contact[1];
              break;

              case "Company":
                    $company = $data[$c];


              case "Address1":
              //store
                    $address1 = $data[$c];

              break;

              case "Address2":
                    $address2 = $data[$c];

              break;

              case "Address3":
                    $address3 = $data[$c];

              break;

              case "City":
                    $city = $data[$c];

              break;

              case "State":
                    $state = $data[$c];

              break;

              case "Zip":
                    $zip = $data[$c];

              break;

              case "Phone1":
                    $phone1 = $data[$c];
              break;

              case "Phone2":
                     $phone2 = $data[$c];
              break; 

              case "Phone 3":
                    $phone3 = $data[$c];
              break;

              case "Fax":
                    $fax = $data[$c];
              break;          

              case "Accountno":
                    $accountNo = $data[$c];
              break;

              default:
                $junk = $data[$c];
              break;


             }




        }       
        echo $company;  
            $meta = serialize(Array(
                    "firstname" => $firstName,
                    "lastname" => $lastName,
                    "lawfirmname" => $company,
                    'address' => $address1,
                    'city' => $city,
                    'state' => $state,
                    'zip' => $zip,
                    'fulladdress' => '',
                    'officenumber' => $phone1,
                    'faxnumber' => $fax,
                    'mobilenumber' => $phone2,
                    'email' =>'nothing',
                    'website' => 'somthing.com',
                    'privacy' => 0,
                    'status' =>1
                    )); 




        mysql_query("INSERT INTO `mg_profiles` (meta) VALUES ($meta)");
        mysql_error();

    }
    fclose($handle);
    }


?>

Leave a Reply

*

Hire Me
Follow Me!
Search
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.
Categories