{"id":18,"date":"2023-10-13T05:54:02","date_gmt":"2023-10-13T05:54:02","guid":{"rendered":"https:\/\/push-demo.lhkpush.com\/amp-demo\/?p=18"},"modified":"2023-10-13T05:54:02","modified_gmt":"2023-10-13T05:54:02","slug":"code","status":"publish","type":"post","link":"https:\/\/push-demo.lhkpush.com\/amp-demo\/2023\/10\/13\/code\/","title":{"rendered":"code"},"content":{"rendered":"<p>&lt;?php<br \/>\n\/\/ Load the database configuration file<br \/>\ninclude_once &#8216;config.php&#8217;;<\/p>\n<p>if(isset($_POST[&#8216;importSubmit&#8217;])){<\/p>\n<p>\/\/ Allowed mime types<br \/>\n$csvMimes = array(&#8216;text\/x-comma-separated-values&#8217;, &#8216;text\/comma-separated-values&#8217;, &#8216;application\/octet-stream&#8217;, &#8216;application\/vnd.ms-excel&#8217;, &#8216;application\/x-csv&#8217;, &#8216;text\/x-csv&#8217;, &#8216;text\/csv&#8217;, &#8216;application\/csv&#8217;, &#8216;application\/excel&#8217;, &#8216;application\/vnd.msexcel&#8217;, &#8216;text\/plain&#8217;);<\/p>\n<p>\/\/ Validate whether selected file is a CSV file<br \/>\nif(!empty($_FILES[&#8216;file&#8217;][&#8216;name&#8217;]) &amp;&amp; in_array($_FILES[&#8216;file&#8217;][&#8216;type&#8217;], $csvMimes)){<\/p>\n<p>\/\/ If the file is uploaded<br \/>\nif(is_uploaded_file($_FILES[&#8216;file&#8217;][&#8216;tmp_name&#8217;])){<\/p>\n<p>\/\/ Open uploaded CSV file with read-only mode<br \/>\n$csvFile = fopen($_FILES[&#8216;file&#8217;][&#8216;tmp_name&#8217;], &#8216;r&#8217;);<\/p>\n<p>\/\/ Skip the first line<br \/>\nfgetcsv($csvFile);<\/p>\n<p>\/\/ Parse data from CSV file line by line<br \/>\nwhile(($line = fgetcsv($csvFile)) !== FALSE){<br \/>\n\/\/ Get row data<br \/>\n$employee_code = $line[0];<br \/>\n$name = $line[1];<br \/>\n$dept = strtoupper($line[2]);<br \/>\n$position = $line[3];<br \/>\n$email = $line[4];<br \/>\n$phone = $line[5];<br \/>\n$isHod = $line[6];<\/p>\n<p>$password = md5(&#8216;1234567&#8217;);<\/p>\n<p>$deptNo = mysqli_fetch_assoc(mysqli_query($conn,&#8221;SELECT * FROM `department` where UPPER(name)=&#8217;$dept'&#8221;))[&#8216;id&#8217;];<\/p>\n<p>if(mysqli_num_rows(mysqli_query($conn,&#8221;SELECT * FROM `employees` WHERE `employee_code`=&#8217;$employee_code'&#8221;))&gt;0)<br \/>\n{<br \/>\necho $employee_code.&#8221; already inserted!&lt;br&gt;&#8221;;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif(mysqli_query($conn,&#8221;INSERT INTO `employees`(`employee_code`, `name`, `employee_pos`, `email`, `password`, `contact`, `ishod`, `dept`, `status`) VALUES (&#8216;$employee_code&#8217;,&#8217;$name&#8217;,&#8217;$position&#8217;,&#8217;$email&#8217;,&#8217;$password&#8217;,&#8217;$phone&#8217;,&#8217;$isHod&#8217;,&#8217;$deptNo&#8217;,&#8217;1&#8242;)&#8221;))<br \/>\n{<br \/>\necho $employee_code.&#8221; inserted&#8212;&#8212;-!&lt;br&gt;&#8221;;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\necho &#8220;Something went wrong&#8212;&#8212;-&lt;br&gt;&#8221;;<br \/>\n}<br \/>\n}<\/p>\n<p>}<\/p>\n<p>\/\/ Close opened CSV file<br \/>\nfclose($csvFile);<\/p>\n<p>$qstring = &#8216;?status=succ&#8217;;<br \/>\n}else{<br \/>\n$qstring = &#8216;?status=err&#8217;;<br \/>\n}<br \/>\n}else{<br \/>\n$qstring = &#8216;?status=invalid_file&#8217;;<br \/>\n}<br \/>\n}<br \/>\n?&gt;<\/p>\n<p>&lt;html&gt;<br \/>\n&lt;head&gt;<\/p>\n<p>&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;form method=&#8221;POST&#8221; enctype=&#8217;multipart\/form-data&#8217;&gt;<br \/>\n&lt;input type=&#8221;file&#8221; name=&#8221;file&#8221;&gt;<br \/>\n&lt;button type=&#8221;submit&#8221; name=&#8221;importSubmit&#8221;&gt;Upload data&lt;\/button&gt;<br \/>\n&lt;\/form&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;?php \/\/ Load the database configuration file include_once &#8216;config.php&#8217;; if(isset($_POST[&#8216;importSubmit&#8217;])){ \/\/ Allowed mime types $csvMimes = array(&#8216;text\/x-comma-separated-values&#8217;, &#8216;text\/comma-separated-values&#8217;, &#8216;application\/octet-stream&#8217;, &#8216;application\/vnd.ms-excel&#8217;, &#8216;application\/x-csv&#8217;, &#8216;text\/x-csv&#8217;, &#8216;text\/csv&#8217;, &#8216;application\/csv&#8217;, &#8216;application\/excel&#8217;, &#8216;application\/vnd.msexcel&#8217;, &#8216;text\/plain&#8217;); \/\/ Validate whether selected file is a CSV file if(!empty($_FILES[&#8216;file&#8217;][&#8216;name&#8217;]) &amp;&amp; in_array($_FILES[&#8216;file&#8217;][&#8216;type&#8217;], $csvMimes)){ \/\/ If the file is uploaded if(is_uploaded_file($_FILES[&#8216;file&#8217;][&#8216;tmp_name&#8217;])){ \/\/ Open uploaded CSV file with read-only mode &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/push-demo.lhkpush.com\/amp-demo\/2023\/10\/13\/code\/\"> <span class=\"screen-reader-text\">code<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","footnotes":""},"categories":[1],"tags":[],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/push-demo.lhkpush.com\/amp-demo\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/push-demo.lhkpush.com\/amp-demo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/push-demo.lhkpush.com\/amp-demo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/push-demo.lhkpush.com\/amp-demo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/push-demo.lhkpush.com\/amp-demo\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":1,"href":"https:\/\/push-demo.lhkpush.com\/amp-demo\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"predecessor-version":[{"id":19,"href":"https:\/\/push-demo.lhkpush.com\/amp-demo\/wp-json\/wp\/v2\/posts\/18\/revisions\/19"}],"wp:attachment":[{"href":"https:\/\/push-demo.lhkpush.com\/amp-demo\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/push-demo.lhkpush.com\/amp-demo\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/push-demo.lhkpush.com\/amp-demo\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}