Getting closer...
The SQL statemnet looks a little better now, I just have to figure out how how to put quotes around the values...
here is the code:
PHP Code:
include 'db_connect_item.php';
$table = "pr_item";
$data = explode("\r\n", $_POST['csv']); //the arguments are reversed
for($i = 0; $i < count($data); $i++) {
$sql = 'INSERT INTO '. $table . '(v1, v2, v3, v4, v5, v6, v7, v8, v10, v11, v12 ) VALUES (';
$thisrow = explode(";", $data[$i]);
for($j = 0; $j < count($thisrow); $j++)
$sql .= mysql_real_escape_string($thisrow[$j]) . ($j != count($thisrow) - 1 ? ", " : ""); //I'll need to include the quotation marks in here
$sql .= ');';
mysql_query($sql) or die ("nice try but: ".mysql_error());
}
//echo "$sql";
that code will give you this:
INSERT INTO pr_item(v1, v2, v3, v4, v5, v6, v7, v8, v10, v11, v12 ) VALUES (, 5555555, 55555, 555, 555, 555, 05/05, 05/02, 05/05, 05/05, 05/05, 55667799);
I think it would be a better idea to have my data already surrounded by quotes (using JS; when the HTML is being converted to CSV), then I think the above code will suffice...
any suggestions?
Rory
Bookmarks