-1

My purpose is to read an excel (.xls) file and store it in the database as well as show the inputs of excel file in the browser.

I am facing problem while reading the file. I have integrated Excelfilereader.php

The program reads the excel file but while printing its output in (excel file content) in the browser, data print in zig-zag way.

Example:

studentid name class school course address [name of fields]

In Browser, the same fields are printed, but the data of studentID is printed under the name, data of name prints under class, but rest all are printed as it is. In first two columns are printed unaligned.

Code used to call Excelreader.php:

[mysql_query("insert into submit_form(parent_id,name,lab,submission,title,sampletype,file) values('','".$_POST['name']."','".$_POST['lab']."','".$_POST['submission']."','".$_POST['title']."','".$_POST['sampletype']."','".$uploadfile."')");
$insertid=mysql_insert_id();
    $data = new Spreadsheet_Excel_Reader($_FILES['uploadfile']['name']);
//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=2;$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>";
            }
            $data->sheets[$i][cells][$j][1];
            $eid = $eid = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][1]);
            $age = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][2]);
            $gender = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][3]);
            $ethnic = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][4]);
            $cancer = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][5]);
            $sample = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][6]);
            $instrument = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][7]);
            $instrumenttype = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][8]);
            $query = "insert into submit_form(parent_id,name,lab,submission,title,patient,age,gender,ethnic,cancer,sample,instrument,instrumenttype,attach,sampletype,file) values('".$insertid."','".$_POST['name']."','".$_POST['lab']."','".$_POST['submission']."','".$_POST['title']."','".$eid."','".$age."','".$gender."','".$ethnic."','".$cancer."','".$sample."','".$instrument."','".$instrumenttype."','1','".$_POST['sampletype']."','".$uploadfile."')";

            mysqli_query($connection,$query);

            $html.="</tr>";
        }
    }][2]
4
  • patient age gender ethnic university 1 23MALE berlin xavier 2 25FEMALE munchen xavier ........ and so on ,,
    – Cammer
    Commented Feb 9, 2016 at 14:33
  • any other solutions please ?
    – Cammer
    Commented Feb 9, 2016 at 14:43
  • Ah, so gender and age are grouped together? What is the outcome of $data->sheets[$i][cells][$j] when you dump it?
    – Matheno
    Commented Feb 9, 2016 at 15:01
  • You've tagged this with "phpMyAdmin" so I suggest you use the phpMyAdmin Import tab; the easiest way is probably to do a CSV export from Excel and import in to phpMyAdmin. Commented Feb 12, 2016 at 20:59

1 Answer 1

0

You have mixed mysql_* calls with mysqli_* calls. Use only mysqli_* calls.

(And you should escape the $_POST[] columns, too. They are vulnerable to hackers.)

1
  • where I have used mysql_* instead of mysqli_* ??
    – Cammer
    Commented Feb 11, 2016 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.