1

I have to upload excel files record into mysql and i have written the following code which is working fine...

<?php

ini_set("display_errors",1);
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
        { 
            $html.="<tr>";
            for($k=1;$k<=count($data->sheets[$i][cells][$j]);$k++) // This loop is created to get data in a table format.
            {
                $html.="<td>";
                $html.=$data->sheets[$i][cells][$j][$k];
                $html.="</td>";
            }
        $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."')";

            mysqli_query($connection,$query);
            $html.="</tr>";
        }
    }

}

$html.="</table>";
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?

1 Answer 1

2

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]);
Sign up to request clarification or add additional context in comments.

1 Comment

thanks but while the table is showing the fourth column is coming blank

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.