Jump to content

help with form


vang163

Recommended Posts

hi,

i'm trying to import data from a txt file to a database. But i'm encountering problem. The data was not added and i could not see any messages. Below is my code, pls advise where i have done wrong, thanks.

 

form.php

session_start();
<form id="Form1" name="Form1" method="post" action="importdata.php">
   <table>
    <tr>
     <td> </td>
     <td><input name="importCSV" type="file"></td>
     <td> </td>
    </tr>
    <tr>
     <th> </th>
     <td><input type="submit" name="Submit" value="Import data" size="40"></td>
     <td> </td>
    </tr>

 

process the form - importdata.php

...
$message = array();
$row = 0;
$importFile = $_POST['importCSV'];
$handle = fopen("$importFile", "r");

while ($data = fgetcsv($handle, 1000, ","))
{	set_time_limit(50);
$query = "INSERT into user (`From`, `To`, `owner`, `countryCode`, `country`) VALUES('".$data[0]."', '".$data[1]."', '".$data[2]."', '".$data[4]."', '".addslashes($data[6])."')";

$result = mysql_query($query) or die("Query failed.");

$message[] = "Row " . $row . " data added.";

$row++;
}

fclose ($handle);

$message[] = 'Import completed! ' . $row . ' rows added to database.';
$_SESSION['MESSAGE'] = $message;
session_write_close();
header("location: form.php");
exit();	
?>

Link to comment
https://forums.phpfreaks.com/topic/118288-help-with-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.