Guest User

Untitled

a guest
Jan 16th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. Server: Localhost via UNIX socket
  2. Server type: MySQL
  3. Server version: 5.7.20-0ubuntu0.16.04.1 - (Ubuntu)
  4. Protocol version: 10
  5. User:
  6. Server charset: UTF-8 Unicode (utf8)
  7.  
  8. Apache/2.4.18 (Ubuntu)
  9. Database client version: libmysql - mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
  10. PHP extension: mysqli Documentation
  11. PHP version: 5.6.33-1+ubuntu16.04.1+deb.sury.org+1
  12.  
  13. <html>
  14. <head>
  15. <title>Save Excel file details to the database</title>
  16. </head>
  17. <body>
  18. <?php
  19. error_reporting(E_ALL); ini_set('display_errors', '1');
  20. $servername = "localhost";
  21. $username = "";
  22. $password = "";
  23.  
  24. // Create connection
  25. $conn = new mysqli($servername, $username, $password);
  26.  
  27. include 'reader.php';
  28. $excel = new Spreadsheet_Excel_Reader();
  29. ?>
  30. <table border="1">
  31. <?php
  32. $excel->read('collegec_database_digitalocean.xls');
  33. $x=2;
  34. while($x<=$excel->sheets[0]['numRows']) {
  35. $id = isset($excel->sheets[0]['cells'][$x][1]) ? $excel->sheets[0]['cells'][$x][1] : '';
  36. $name = isset($excel->sheets[0]['cells'][$x][2]) ? $excel->sheets[0]['cells'][$x][2] : '';
  37. $describtion = isset($excel->sheets[0]['cells'][$x][3]) ? $excel->sheets[0]['cells'][$x][3] : '';
  38. $email = isset($excel->sheets[0]['cells'][$x][4]) ? $excel->sheets[0]['cells'][$x][4] : '';
  39. $phone = isset($excel->sheets[0]['cells'][$x][5]) ? $excel->sheets[0]['cells'][$x][5] : '';
  40. $website = isset($excel->sheets[0]['cells'][$x][6]) ? $excel->sheets[0]['cells'][$x][6] : '';
  41. $location = isset($excel->sheets[0]['cells'][$x][7]) ? $excel->sheets[0]['cells'][$x][7] : '';
  42. $postgraduatecourses = isset($excel->sheets[0]['cells'][$x][8]) ? $excel->sheets[0]['cells'][$x][8] : '';
  43. $shortcoursesandcertifications = isset($excel->sheets[0]['cells'][$x][9]) ? $excel->sheets[0]['cells'][$x][9] : '';
  44. $technicalandvocationalcourses = isset($excel->sheets[0]['cells'][$x][10]) ? $excel->sheets[0]['cells'][$x][10] : '';
  45. $fees = isset($excel->sheets[0]['cells'][$x][2]) ? $excel->sheets[0]['cells'][$x][11] : '';
  46. $undergraduatecourses = isset($excel->sheets[0]['cells'][$x][12]) ? $excel->sheets[0]['cells'][$x][12] : '';
  47.  
  48. // Save details
  49. $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')";
  50.  
  51. if (mysqli_query($conn, $sql_insert)) {
  52. echo "New record created successfully";
  53. } else {
  54. echo "Error: " . $sql_insert . "<br>" . mysqli_error($conn);
  55. }
  56.  
  57.  
  58. $x++;
  59. }
  60. mysqli_close($conn);
  61. ?>
  62. </table>
  63.  
  64. </body>
  65. </html>
Add Comment
Please, Sign In to add comment