hey guys i have a little script im working on to upload a xls file and insert the data in mysql..
this is what i have:
$db_username="2"; //database user name
$db_password="2";//database password
$db_database="2"; //database name
$db_host="localhost";
mysql_connect($db_host,$db_username,$db_password);
@mysql_select_db($db_database) or die( "Unable to connect to database.");
$handle = fopen("/Upload_/test.xls", "r"); //test.xls excel file name
if ($handle)
{
$array = explode("\n", fread($handle, filesize("test.xls")));
}
$total_array = count($array);
$i = 0;
while($i < $total_array)
{
$data = explode(",", $array[$i]);
$sql = "insert into test (`nom` ,`prenom` ) values ('$data[0]','$data[1]')"; // i have two fields only , in oyour case depends on your table structure
$result = mysql_query($sql);
$i++;
}
echo "completed";
but i get this..
id nom prenom
Edit Inline Edit Copy Delete 1 ????
Edit Inline Edit Copy Delete 2 DROID TECH 8?rCal
Edit Inline Edit Copy Delete 3 ?rCalib ##0_);("$"#
Edit Inline Edit Copy Delete 4 ?? ?? ?
Edit Inline Edit Copy Delete 5 ?}
Edit Inline Edit Copy Delete 6 ????}
Edit Inline Edit Copy Delete 7 ?}
Edit Inline Edit Copy Delete 8 ????}
how did i get to this?
my xls file looks like this
1 2441343 techker techker
2 .... ... ...
3 ...
so i set the insert to utf-8 with
$link = mysql_connect("localhost", "1", "2");
mysql_set_charset('utf8',$link);
$db_selected = mysql_select_db("2", $link);
if (!$db_selected) { die ('Database access error : ' . mysql_error());}
but i still get that funky characters..