user3305327 user3305327 - 4 months ago 9x
PHP Question

Excel to MySQL using PHP

I have to upload excel files record into

and i have written the following code which is working fine...


require_once 'excel_reader2.php';
require_once 'db.php';

$data = new Spreadsheet_Excel_Reader("file.xls");

echo "Total Sheets in this xls file: ".count($data->sheets)."<br /><br />";

$html="<table border='1'>";
for($i=0;$i<count($data->sheets);$i++) // Loop to get all sheets in a file.
if(count($data->sheets[$i][cells])>0) // checking sheet not empty
echo "Sheet $i:<br /><br />Total rows in sheet $i ".count($data->sheets[$i][cells])."<br />";
for($j=1;$j<=count($data->sheets[$i][cells]);$j++) // loop used to get each row of the sheet
for($k=1;$k<=count($data->sheets[$i][cells][$j]);$k++) // This loop is created to get data in a table format.
$Productcode = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][1]);
$Artikel = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][2]);
$EANcode = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][3]);
$url_kiesk_nl = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][4]);

$query = "insert into test(Productcode,Artikel,EANcode,url_kiesk_nl) values('".$Productcode."','".$Artikel."','".$EANcode."','".$url_kiesk_nl."')";



echo $html;
echo "<br />Data Inserted in dababase";

Now I have to add a word into the 4th column for each record for that I have written this line. Actually my requirement is to add "1" to each cells of 4th column.

$url_kiesk_nl = mysqli_real_escape_string($connection,$data->"1".sheets[$i][cells][$j][4]);

But this is not working... can anyone please help me?

lpg lpg

Use this:

$url_kiesk_nl = "1".mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][4]);

Or this:

$url_kiesk_nl = mysqli_real_escape_string($connection,"1".$data->sheets[$i][cells][$j][4]);