Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Server: Localhost via UNIX socket
- Server type: MySQL
- Server version: 5.7.20-0ubuntu0.16.04.1 - (Ubuntu)
- Protocol version: 10
- User:
- Server charset: UTF-8 Unicode (utf8)
- Apache/2.4.18 (Ubuntu)
- Database client version: libmysql - mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
- PHP extension: mysqli Documentation
- PHP version: 5.6.33-1+ubuntu16.04.1+deb.sury.org+1
- <html>
- <head>
- <title>Save Excel file details to the database</title>
- </head>
- <body>
- <?php
- error_reporting(E_ALL); ini_set('display_errors', '1');
- $servername = "localhost";
- $username = "";
- $password = "";
- // Create connection
- $conn = new mysqli($servername, $username, $password);
- include 'reader.php';
- $excel = new Spreadsheet_Excel_Reader();
- ?>
- <table border="1">
- <?php
- $excel->read('collegec_database_digitalocean.xls');
- $x=2;
- while($x<=$excel->sheets[0]['numRows']) {
- $id = isset($excel->sheets[0]['cells'][$x][1]) ? $excel->sheets[0]['cells'][$x][1] : '';
- $name = isset($excel->sheets[0]['cells'][$x][2]) ? $excel->sheets[0]['cells'][$x][2] : '';
- $describtion = isset($excel->sheets[0]['cells'][$x][3]) ? $excel->sheets[0]['cells'][$x][3] : '';
- $email = isset($excel->sheets[0]['cells'][$x][4]) ? $excel->sheets[0]['cells'][$x][4] : '';
- $phone = isset($excel->sheets[0]['cells'][$x][5]) ? $excel->sheets[0]['cells'][$x][5] : '';
- $website = isset($excel->sheets[0]['cells'][$x][6]) ? $excel->sheets[0]['cells'][$x][6] : '';
- $location = isset($excel->sheets[0]['cells'][$x][7]) ? $excel->sheets[0]['cells'][$x][7] : '';
- $postgraduatecourses = isset($excel->sheets[0]['cells'][$x][8]) ? $excel->sheets[0]['cells'][$x][8] : '';
- $shortcoursesandcertifications = isset($excel->sheets[0]['cells'][$x][9]) ? $excel->sheets[0]['cells'][$x][9] : '';
- $technicalandvocationalcourses = isset($excel->sheets[0]['cells'][$x][10]) ? $excel->sheets[0]['cells'][$x][10] : '';
- $fees = isset($excel->sheets[0]['cells'][$x][2]) ? $excel->sheets[0]['cells'][$x][11] : '';
- $undergraduatecourses = isset($excel->sheets[0]['cells'][$x][12]) ? $excel->sheets[0]['cells'][$x][12] : '';
- // Save details
- $sql_insert="INSERT INTO collegec_SchoolDir (id,name,describtion,email,phone,website,location,postgraduatecourses,shortcoursesandcertifications,technicalandvocationalcourses,fees,undergraduatecourses) VALUES ('','$name','$describtion','$email','$phone','$website','$location','$postgraduatecourses','$shortcoursesandcertifications','$technicalandvocationalcourses','$fees','$undergraduatecourses')";
- if (mysqli_query($conn, $sql_insert)) {
- echo "New record created successfully";
- } else {
- echo "Error: " . $sql_insert . "<br>" . mysqli_error($conn);
- }
- $x++;
- }
- mysqli_close($conn);
- ?>
- </table>
- </body>
- </html>
Add Comment
Please, Sign In to add comment