Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8839359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:13:18+00:00 2026-06-14T10:13:18+00:00

Hello to all this is my first time posting, thought it would be good

  • 0

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);
    }


?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:13:19+00:00Added an answer on June 14, 2026 at 10:13 am

    If every else variables are existing and works correctly, then the missing break; should be the problem on the case of Company.

    It is not a good idea to communicate with a relational database within a loop, it is more memory and process efficient to store the results to an array and after all data has ben got, just insert with a simple request, because

    INSERT INTO `mg_profiles` (meta) VALUES (...), (...), (...)
    

    works perfectly.

    PHP has a command to handle processes like this:

    while (($data = fgetcsv($handle, 1000, ",")) !== false) {
        if ($row == 1 || $row == 2) {
            $row++;
            continue;
        }
        list ($contact, $company, $address1 /*, ...*/) = $data;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i am little new to all this but i want to know that:
Hello all! This is my first post on stackoverflow. After hours of searching and
Hello Good People !! I have a web application (my first of this type)
hello all this seems to be my problem I have a table in mysql
Problem Hello all! I have this code which takes my jpg image loops through
Hello I currently have this code checking if a cookie exists, it works all
Hell All, So I have been facing this behavior for quite some time and
I'm still working on my first Grails application. This time, my problem is to
this is my first time trying to use java for backend web systems. I
First of all, hello. I've been trying to achieve something in quite a long

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.