Jump to content

Getting CSV text into variables so i can insert into database


AdRock

Recommended Posts

I have a CSV file and I want to get each part of the line of text into different variables

 

I have found some code but can't get it to put into seperate variables

 

I have a form with 2 fields where the user can add there own data but if they click a button iwant this function called

 

    function get_start() {
$file_handle = fopen("test.csv", "r");
while (!feof($file_handle) ) {
    $line_of_text = fgetcsv($file_handle, 1024);
    $s_lat == $line_of_text[0];
    $s_long == $line_of_text[1];
}
fclose($file_handle);
    }

 

here is a cut down version of my code

    $s_lat = $_POST['s_lat'];  // what the user can enter
    $s_long = $_POST['s_long'];   // what the user can enter
    //variables for end of route
    $e_street = $_POST['e_street'];
    $e_postcode = $_POST['e_postcode'];
    $e_lat = $_POST['e_lat'];   // what the user can enter
    $e_long = $_POST['e_long'];   // what the user can enter
    //variable for departure time
    $depart = $_POST['time'];

    function get_start() {
$file_handle = fopen("test.csv", "r");
while (!feof($file_handle) ) {
    $line_of_text = fgetcsv($file_handle, 1024);
    $s_lat == $line_of_text[0];
    $s_long == $line_of_text[1];
    print $s_lat." ".$s_long;
}
fclose($file_handle);
    }

    function get_end() {  
        $file_handle = fopen("test.csv", "r");
while (!feof($file_handle) ) {
    $line_of_text = fgetcsv($file_handle, 1024);
    $e_lat == $parts[0];
    $e_long == $parts[1];
    
}
fclose($file_handle);
    }

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.