New to our community ?

Discover a world of possibilities! Join us and explore a vibrant community where ideas flourish and connections thrive.

One of Our Valued Members

Thank you for being part of our community. Your presence enriches our shared experiences. Let's continue this journey together!

Home Blog Page 11

How to read and insert an excel file data into MySQL.

Welcome back to shortlearner.com, in this post we will learn how to read an excel file and insert the excel data into MySQL with the help of PHP Excel library.

read and insert an excel file data into MySQL

 Now a days i am working on a project of one of my client and he has a bulk amount of data in excel(.xlsx) format.
he wants to insert all his data into database using single process to save his time.

Also Read :
Get Domain name from URL
How to Send Attachment on mail using PHP.
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

Hence, we have created a process which fulfills our client requirement.
So, in this post we are going to share the way

how we can achieve the same. You can also try the same way which will save your time and easy to implement.


Below is the example of inserting excel data into mysql with the help of PHPExcel library.
Short overview of our working flow:


1.Create database and it’s tables.
2.Download php excel library.
3.Write a code which helps to import data into database and also shows the excel data into our webpage.


Here is the way to implement the flow :
We are creating a database named jyotishi and also creating a table ank_jyotishkosh into our database.

CREATE TABLE `ank_jyotishkosh` (
  `id` int(11) NOT NULL,
  `word` longtext,
  `image` varchar(255) NOT NULL,
  `structure` longtext,
  `meaning` longtext,
  `extra` longtext,
  `search` longtext,
  `lang` varchar(255) NOT NULL DEFAULT 'hindi',
  `status` varchar(255) NOT NULL DEFAULT 'active'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

we move to our second step and download the PHPExcel library click here to download PHPExcel library .

We are creating a config.php file, which helps to make a connection to our MySQL database.

<?php 
$con = mysqli_connect("localhost","root","rootroot","jyotishi");
 ?>

Now we are creating another PHP file where we write a code for import data into database and shows the data into web page as well.

we are creating a form in bootstrap which takes excel file from user and also add some bootstrap maxcdn files and custom CSS as well.

<!DOCTYPE html>
  <html>
  	<head>
    	<title>Import Excel data into mysql database</title>
    	<style>
		  body
		  {
		   margin:0;
		   padding:0;
		   background-color:#f1f1f1;
		  }
		  .box
		  {
		   width:700px;
		   border:1px solid #ccc;
		   background-color:#fff;
		   border-radius:5px;
		   margin-top:100px;
		  }
	  	</style>
  	</head>
  	<body>
  		<div class="container box"> <h3 align="center">Please Upload Only Excel File</h3><br />
   			<form method="post" enctype="multipart/form-data">
			    <label>Select Excel File</label>
			    <input type="file" name="excel" required/ >
			    <br />
		    	<input type="submit" name="import" class="btn btn-info" value="Import" />
		   	</form>
		   <br />
		   <br />
			<?php echo $output; ?>
  		</div>
  	</body>
</html>

In the above code you can see a php variable $output at the end of the code, which will use for showing excel data into web page.

Now move to the next step, when user hit on the import button then it checks whether the file is in the excel format or not.


If the file is in excel format then we move further otherwise it will show an error message and requests user to select valid excel file.

If user select valid excel file then we will include our php excel libaray into our code.

We put our data into PHP variable with the help of foreach loop and then shows in a table format and write an insert query which insert our data into database too.

<?php
if(isset($_POST["import"]))
{
require('config.php');
	$output = '';
	$file_name  = $_FILES["excel"]["name"];
	$tmp = explode('.', $file_name);
	$extension = end($tmp);
	$allowed_extension = array("xls", "xlsx", "csv"); //allowed extension
	if(in_array($extension, $allowed_extension)) //check selected file extension is present in allowed extension array
	{
		$file = $_FILES["excel"]["tmp_name"]; // getting temporary source of excel file
		include("PHPExcel-1.8/Classes/PHPExcel/IOFactory.php"); // Add PHPExcel Library in this code
		$objPHPExcel = PHPExcel_IOFactory::load($file);
		$output .= "<label class='text-success'>Data Inserted</label><br /><div class='container'><div class='row'><table class='table table-bordered'><tr><th>Word</th><th>Meaning</th><th>Extra</th></tr>";
		foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
		{
			$highestRow = $worksheet->getHighestRow();
			for($row=2; $row<=$highestRow; $row++)
			{
				$output .= "<tr>";
				$word = mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(0, $row)->getValue());
				$image = mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(1, $row)->getValue());
				$structure = mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(2, $row)->getValue());
				$meaning = mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(3, $row)->getValue());
				$extra = mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(4, $row)->getValue());
				$search = mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(5, $row)->getValue());
				$lang = mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(6, $row)->getValue());
				$status = mysqli_real_escape_string($con, $worksheet->getCellByColumnAndRow(7, $row)->getValue());
				mysqli_set_charset($con,'utf8'); 
				$query = "insert into ank_jyotishkosh(word,image,structure,meaning,extra,search,lang,status) values('".$word."','".$image."','".$structure."','".$meaning."','".$extra."','".$search."','".$lang."','".$status."')";
  				mysqli_query($con, $query);
			    $output .= '<td>'.$word.'</td>';
			    $output .= '<td>'.$meaning.'</td>';
			    $output .= '<td>'.$extra.'</td>';
    			$output .= '</tr>';
   			}
  		} 
  		$output .= '</table></div></div>';
	}
	else
	{
		$output = '<label class="text-danger">Invalid File</label>'; //if non excel file then
	}
}
?>

Note : When you run this code and got some error then please make sure you have enabled zip extension on your server.This is the common error which we receive.


If you would like to know how to check whether extension is enabled or not, please check our post on how to enable extension on server.


Keep learning.
Stay connected with us for any queries.

Enable PHP Zip Extension through cPanel

0

Welcome back to shortlearner.com, in this post we will see how to enable PHP ZIP extension on cPanel.
before start this tutorial, we should take a overview about PHP extension.
so basically PHP extension enables you to transparently read or write ZIP compressed archives and the files inside them.

how to enable extensions in cpanel


and most of the time it is disable by default in cPanel , so we have to manually install it.
So just follow the steps and install these extensions manually.
Note: try to follow snaps for better understanding.

step 1: So in the very first step , we should login into our cPanel(Control Panel) and than go to the software section
Step 2: in the software section click on PHP Pear Packages

Enable PHP ZIP Extensions in cPanel

Also Read :
Get Domain name from URL
How to Send Attachment on mail using PHP.
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

Step3: after clicking on PHP Pear Packages we are searching our ZIP extension and install it.

enable php extension

step 4 : After installing the package we should again go to our software section and click on the PHP version .

install zip archive

Step5: once we click on the select PHP Version, we can see all the enable extension over there, and we can see our Archiv_ZIP as well. so we just checked it and hit on the save button to add archive_zip in our current PHP version.

enable php zip extension

Step5: now the last and very important step we will follow to complete this tutorial.again go to the software section and click on the PHP processes and hit the kill process button.

zip enable in cpanel

Now we can use your PHP ZIP Extension our website.

भोपाल जॉब सीकर्स (मध्य प्रदेश का नंबर एक सोशल मीडिया जॉब सीकर ग्रुप )

0

सोशल मीडिया : आज के दिनों में हर कोई व्यक्ति अपनी सुबह की शुरुआत सोशल मीडिया को चेक करने के साथ ही करता है , सोशल मीडिया का अगर सही तरीके से उपयोग किया जाये तो ये हमे बहुत रोचक जानकारिया उपलबध करवाता है , आज लॉक डाउन के समय में बहुत सारे सरकारी और सामाजिक संस्थाए सोशल मीडिया की मदद से ही लोगो को जागरूक कर रही है , उन्हें जरुरत सेवाएं मुहैया करवा रही है, बहुत सारे फेसबुक ग्रुप है जो लोगो को लाइव सेशन के माध्यम से लोगो में जागरूकता फैला रहे है , उन्ही में से एक ग्रुप है भोपाल जॉब सीकर्स जो पिछले ५ सालो से फेसबुक के माध्यम से स्टूडेंट्स की मदद कर रहा है |

इस ग्रुप को बनाने वाले एडमिन बताते है की उन्होंने इस ग्रुप की शुरुआत जुलाई २०१५ में की थी , पहले ये ग्रुप भोपाल के लोगो के लिए ही बनाया था ,लेकिन इस ग्रुप का नाम और प्रशंसा ऐसी फैलती गयी की अब यह ग्रुप भारत के कोने-कोने में जानने लगा है| ये ग्रुप हजारों चेहरों की मुस्कान बना है, बहुत से लोगो को इस ग्रुप के माध्यम से जॉब मिली है और कंपनी को उनके अच्छे कैंडिडेट्स मिले है| यह एक फेसबुक ग्रुप है जिसमे १ लाख से ज्यादा लोग जुड़े हुए है| इसमें नौकरी से सम्बन्धी सभी प्रकार की जानकारी दी जाती है|

success stories

इस पोर्टल के माध्यम से ओपन कैंपस ड्राइव, रेफरल ड्राइव , ऑफलाइन ड्राइव की सचुना
,सरकारी नौकरी की जानकारी विभिन्न स्रोतो से संग्रह कर के नौकरी तलाशने वाले स्टूडेंट्स तक पहुंचे जाती हैऔर कई
बेरोजगरो के लिए उपयोगी साबित हुई है । इस ग्रुप के सक्रीय एडमिन बताते है की २०१५ में जब ये ग्रुप बनाया गया था तब यहाँ सदस्यों की संख्या २००० थी जो प्रतिवर्ष बढ़ती चली गयी और आज ग्रुप से १ लाख से ज्यादा स्टूडेंट्स जुड़े है ।

Also Read

balance life makes us happy and give peace of mind
Story Of Bhopal Job Seekers
Step By step Guide for placement preparation

हरिओम राजपूत
ग्रुप के एडमिन हरिओम राजपूत जो की पेशे से एक मल्टीनेशनल आईटी कंपनी में एक सॉफ्टवेयर इंजीनियर है , वो बताते है की इस ग्रुप की शुरुआत का सबसे प्रमुख कारण यह था की भोपाल में ज्यादातर स्टूडेंट्स को ऑफ ड्राइव का पता नहीं चल पता था , जिससे उन्हें काफी परेशानियों का सामना करना पड़ता था, ड्राइव्स देने उन्हें दिल्ली, मुंबई, पुणे ,बैंगलोर जैसे मेट्रो शहर में जाना पड़ता था ,उनकी मदद के लिए उन्होंने इस ग्रुप की बनाया था , और आज इस ग्रुप की सहायत से हजारो स्टूडेंट्स को कैंपस ड्राइव की जानकारी दी जा रही है ।

ओम बताते है की ये ग्रुप एक सिद्धांत से बनाया गया था की बिना किसी स्वार्थ स्टूडेंट्स की मदद की जाये । बहुत से कंसल्टेंसी हमसे जुड़ना चाह रही है लेकिन हम इक्छुक नहीं है। हमारा उद्देश्य इस ग्रुप से कमाई का जरिया नहीं बनाना
चाहते है। हम लोग को बस लोगो की मदद कर के लोगो केचेहरों की मुस्कान का कारण बनाना है ना की पैसा कामना है।

नेहा अभय
ग्रुप की नेहा अभय झोड़े जो की एक ग्राफ़िक्स डिज़ाइनर है,और एक अच्छी बिज़नेस वीमेन है
। नेहा कहती है ,भोपाल जॉब सीकर्स ग्रुप केमाध्यम से हम लोगो की मदद कर पा रहे है
और इसमें सभी सदस्यों का भी बहुत बड़ा योगदान है। में बहुत खुश हु ,इस ग्रुप के
सदस्य बनकर ,आज में खुद ग्राकिक्स डिज़ाइनर हु और कई देशो के क्लाइंट्स संभाल रही हूाँ

नितिन फरक्या
एडमिन नितिन फरक्या जो की एक बैंक में सेल्स मैनेजर है।
नितिन फरक्या कहतेहै, की यह ग्रुप लोगो को जागरूक करने के लिए बनाया था । सामान्य रूप से
युवाओ को अधिक जानकारी नहीं होती है और आम तौर पर वे दिशा से भटक जाते है ।इस ग्रुप के माध्यम से लोगो की मदद ले सकते है।हमारी कोशिश यही
रहेगी जब किसी को मदद की जरुरत पड़ेगी हम करेंगे।

ग्रुप में बढ़ते सदस्यों को देखते हुए और नेक इरादे से काम कर रहे एडमिन की सहायता के लिए मोहित दुबे, धर्मेश शर्मा और विकास सिंह राजपूत जो की तीनो पेशे से मल्टीनेशनल आईटी कंपनी में सॉफ्टवेयर इंजीनियर है , अपनी विचारो की साँझा करते हुए बताते है की वे पिछले 2-3 सालो से इस ग्रुप को फॉलो कर रहे थे , बाद में वे इसी ग्रुप के साथ जुड़कर बतौर एडमिन निस्वार्थ काम कर रहे है, और स्टूडेंट्स की मदद करके उन्हें सही दिशा में मार्ग प्रदर्शित कर रहे है ।

Send forgot password by mail script in PHP

0

welcome back to shortlearner.com, in this post we will see how to send forgot password on mail with the help of PHP.
So in the very step we establish our database connection in connection.php file than we include it in our send.php file.
connection.php

orgot password in php
<?php
$server_name='localhost';
$user_name='root';
$password='root';
$db_name = "crud";
$con= mysqli_connect($server_name,$user_name,$password,"$db_name");
if(!$con){
 die('Could not Connect My Sql:' .mysql_error());
}
?>

index.php
Also Read :
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<link rel="stylesheet" href="style.css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->

<div class="container forget-password">
            <div class="row">
                <div class="col-md-12 col-md-offset-4">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <div class="text-center">
                                <img src="https://i.ibb.co/rshckyB/car-key.png" alt="car-key" border="0">
                                <h2 class="text-center">Forgot Password?</h2>
                                <p>You can reset your password here.</p>
                                <form id="register-form" role="form" autocomplete="off" class="form" method="post" action="send.php">
                                    
                                    <div class="form-group">
                                        <div class="input-group">
                                            <span class="input-group-addon"><i class="glyphicon glyphicon-envelope color-blue"></i></span>
                                            <input id="forgetAnswer" name="user_id" placeholder="Username" class="form-control"  type="text">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <input name="btnForget" class="btn btn-lg btn-primary btn-block btnForget" value="Reset Password" type="submit" name="submit">
                                    </div>

                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

style.css

body{
    background:#f3c538;
}
.forget-pwd > a{
    color: #dc3545;
    font-weight: 500;
}
.forget-password .panel-default{
    padding: 31%;
    margin-top: -27%;
}
.forget-password .panel-body{
    padding: 15%;
    margin-bottom: -50%;
    background: #fff;
    border-radius: 5px;
    -webkit-box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
img{
    width:40%;
    margin-bottom:10%;
}
.btnForget{
    background: #c0392b;
    border:none;
}
.forget-password .dropdown{
    width: 100%;
    border: 1px solid #ced4da;
    border-radius: .25rem;
}
.forget-password .dropdown button{
    width: 100%;
}
.forget-password .dropdown ul{
    width: 100%;
}

send.php

<?php
session_start();
include_once 'connection.php';
if(isset($_POST['submit']))
{
    $user_id = $_POST['user_id'];
    $result = mysqli_query($con,"SELECT * FROM user_details where user_id='" . $_POST['user_id'] . "'");
    $row = mysqli_fetch_assoc($result);
	$fetch_user_id=$row['user_id'];
	$email_id=$row['email_id'];
	$password=$row['password'];
	if($user_id==$fetch_user_id) {
				$to = $email_id;
                $subject = "Password";
                $txt = "Your password is : $password.";
                $headers = "From: password@studentstutorial.com" . "\r\n" .
                "CC: somebodyelse@example.com";
                mail($to,$subject,$txt,$headers);
			}
				else{
					echo 'invalid userid';
				}
}
?>

Login with AJAX ,JQuery and PHP.

0

welcome back to shortlearner.com, in our previous post we learn how to create a signup or registration page with the help of AJAX, PHP and MySQL. Now in this post today we will learn how to implement login script with the help of Bootstrap, AJAX, PHP and MySQL.
Before start this tutorial we should know a little bit about AJAX.
so basically it stands for Asynchronous JavaScript and XML.

login using ajax in php

A user can continue to use the application while the client program requests information from the server in the background.
so first we create a database with the name of task, and also create a database table with the name of emp_details.

in this table we take employees personal details like employee name, email, password and mobile number as well.

CREATE TABLE `emp_details` (
  `id` int(11) NOT NULL auto_increment,
  `emp_name` varchar(222) default NULL,
  `email` varchar(222) default NULL,
  `mobile` varchar(22) default NULL,
  `password` varchar(22) default NULL,
  `status` int(10) default '1',
  `user_type` varchar(222) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;

After creating database we need to establish a connection between our PHP code and MySQL database. so we create a config.php page and make a database connection inside it.
config.php

<?php 
$conn = mysqli_connect("localhost","root","root","task");
?>

Also Read :
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

Now we design a responsive login form with the help of bootstrap, html and css.
index.php

<html>
</head>
<link href="style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
	<div class="container login-container">
	    <div class="row">
		    <div class="col-md-6 login-form-1">
		        <h3>Admin Login</h3>
		        <hr>
		        <form id="loginform" method="post" onsubmit="return do_login();">
		            <div class="form-group">
		                <input type="email" class="form-control" name="email" id="email" placeholder="Your Email *" value="" />
		            </div>
		            <div class="form-group">
		                <input type="password" class="form-control" name="password" id="password" placeholder="Your Password *" value="" />
		            </div>
		            <div class="form-group">
		                <input type="submit" class="btnSubmit" value="Login" />
		            </div>
		            <div class="form-group">
		                <a href="#" class="ForgetPwd">Forget Password?</a>
		            </div>
		        </form>
		    </div>
<body>
</html>

and put the css file in style.css

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}

.topnav {
  overflow: hidden;
  background-color: #333;
}

.topnav a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
}

.topnav a:hover {
  background-color: #ddd;
  color: black;
}

.topnav a.active {
  background-color: #4CAF50;
  color: white;
}

.topnav .icon {
  display: none;
}

@media screen and (max-width: 600px) {
  .topnav a:not(:first-child) {display: none;}
  .topnav a.icon {
    float: right;
    display: block;
  }
}

@media screen and (max-width: 600px) {
  .topnav.responsive {position: relative;}
  .topnav.responsive .icon {
    position: absolute;
    right: 0;
    top: 0;
  }
  .topnav.responsive a {
    float: none;
    display: block;
    text-align: left;
  }
}

on form submit we call a JQuery function do_login, which takes all the values of input fields on the behalf of their ids itself, than we send all the data to our do_login.php page using action tag.

<script type="text/javascript">
	function do_login()
	{
		
	 var email=$("#email").val();
	 var pass=$("#password").val();
	 if(email!="" && pass!="")
	 {
	  
	  $.ajax
	  ({
	  type:'post',
	  url:'do_login.php',
	  data:{
	   action:'login',
	   email:email,
	   password:pass
	  },
	  success:function(response) {
	  if(response=="success")
	  {
	    window.location.href="dashboard.php";
	  }
	  else
	  {
	    
	    alert("Wrong Details");
	  }
	  }
	  });
	 }

	 else
	 {
	  alert("Please Fill All The Details");
	 }

	 return false;
	}
</script>

now create our last do_login.php page which will help us to check the users data from database without refreshing current page.
do_login.php

<?php 
if($_POST['action']=='login')
{
	require('config.php');
	$email =  filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
	$password = filter_var($_POST['password']);
	$find = $conn->query("SELECT * FROM emp_details where `email`='$email' AND `password`='$password' AND `status`='1' AND user_type='admin'");
	$fetch = $find->fetch_assoc();
	if($fetch['id'])
	{
		session_start();
		$_SESSION['email'] = $fetch['email'];
		echo "success"; 	
	}
}
?>