Tuesday, 9 August 2016

PHP CODE EXAMPLE FOR IMPORTING CSV FILES

STEP 1:

create table myrecord
(id   int primary key auto_increment,
 name  varchar(200),
city     varchar(200)
);

STEP 2 :now write code for   import.php file:


 <?php
$hostname = "localhost";
$username = "root";
$password = "";
$database = "t";
$conn = mysql_connect("$hostname","$username","$password") or die(mysql_error());
mysql_select_db("$database", $conn) or die(mysql_error());
?>
<html>
<body>

<div >Import Excelsheet Data in mysql table<br><br>
</div>

<form name='import' method='post' enctype='multipart/form-data'>
<input type='file' name='file' /><br />
<input type='submit' name='submit' value='Submit' />
</form>
<?php
if(isset($_POST['submit']))
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file, "r");
$c = 0;
while(($filesop = fgetcsv($handle, 1000,",")) !== false)
{
$name = $filesop[0];
$city = $filesop[1];

$sql = mysql_query("INSERT INTO myrecord (name,city) VALUES ('$name','$city')");
$c = $c + 1;
}

if($sql)
{
echo "You database has imported successfully. You have inserted ". $c ." recoreds";
}
else
{
echo "Sorry! There is some problem.";
}

}
?>

OUPUT:



Tuesday, 2 August 2016

PhpToExcel EXPORT CODING EXAMPLE

(1)write code for connection.php   file:

<?php

                $hostname = "localhost";
                $username = "root";
                $password = "";
                $database = "test";


                 $conn = mysql_connect("$hostname","$username","$password") or die(mysql_error());
                mysql_select_db("$database", $conn) or die(mysql_error());

?>
(2)write code for ExportToExcel.php file:

<?php
function ExportExcel($table)
{

$filename = "uploads/".strtotime("now").'.csv';

$sql = mysql_query("SELECT * FROM $table") or die(mysql_error());

$num_rows = mysql_num_rows($sql);
if($num_rows >= 1)
{
$row = mysql_fetch_assoc($sql);
$fp = fopen($filename, "w");
$seperator = "";
$comma = "";

foreach ($row as $name => $value)
{
$seperator .= $comma . '' .str_replace('', '""', $name);
$comma = ",";
}

$seperator .= "\n";
fputs($fp, $seperator);

mysql_data_seek($sql, 0);
while($row = mysql_fetch_assoc($sql))
{
$seperator = "";
$comma = "";

foreach ($row as $name => $value)
{
$seperator .= $comma . '' .str_replace('', '""', $value);
$comma = ",";
}

$seperator .= "\n";
fputs($fp, $seperator);
}

fclose($fp);
echo "Your file is ready. You can download it from <a href='$filename'>here!</a>";
}
else
{
echo "There is no record in your Database";
}


}
?>

(3)write  code for index.php   file:

<?php

include ("connection.php");
include ("ExportToExcel.php");

if(isset($_POST["submit"]))
{
ExportExcel("myrecord");
  }

?>

<html>
<head>
<style type="text/css">
body
{
margin: 0;
padding: 0;
background-color:#D6F5F5;
text-align:center;
}
.top-bar
{
width: 100%;
height: auto;
text-align: center;
background-color:#FFF;
border-bottom: 1px solid #000;
margin-bottom: 20px;
}
.inside-top-bar
{
margin-top: 5px;
margin-bottom: 5px;
}
.link
{
font-size: 18px;
text-decoration: none;
background-color: #000;
color: #FFF;
padding: 5px;
}
.link:hover
{
background-color: #9688B2;
}
</style>

</head>

<body>

<form name="export" method="post">
    <input type="submit" value="Click Me!" name="submit">
    </form>
   
<hr style="margin-top:300px;" />
   
    <div align="center" style="font-size:18px;"><a href="http://www.phpdevelopmenttricks.blogspot.com">&copy;om sir</a></div>

</body>
</html>




Monday, 1 August 2016

xampp installation on Linux system (Ubuntu)

(1)step 1:

download xampp setup  from
 
url="https://www.apachefriends.org/download.html"


(2)step 2:


jafar@ubuntu-business:~$ sudo su
[sudo] password for jafar:
root@ubuntu-business:/home/jafar# cd  /home/jafar/Downloads
root@ubuntu-business:/home/jafar/Downloads# sudo  chomod 777 -R xampp-linux-5.5.37-0-installer.run
sudo: chomod: command not found
root@ubuntu-business:/home/jafar/Downloads# sudo  chmod 777 -R xampp-linux-5.5.37-0-installer.run
root@ubuntu-business:/home/jafar/Downloads# ./xampp-linux-5.5.37-0-installer.run

(3)step 3 :

after   that    your setup  installation will start cick on "next" and "next and finally click on "finish"  setup..


(4)now  to start  xmapp on ubuntu:

open terminal  & type given below command:


 sudo    /opt/lampp/lampp/  start


(5)how  to create  a  php file :

open terminal   &  type given below command :

cd  \opt\lampp\htdocs\yourprojectfolder

(6)now    type  following command to create   exmaple.php file  inside  your project folder:

cat   >example.php   
and make enter and type following code
<?php

echo  "hello world ";

?>

and  press  CTRL +  D   TO  SAVE  FILE.

(7)NOW OPEN  BROWSER  AND   AND RUN  "exmaple.php"  file.

"Localhost/yourprojectfolder/example.php "




Browsers

Powered by Blogger.

Feature Post

About Me

My photo
B.E.(COMPUTER ENGINEER) PHP Web developer & Provide Training for Web Development , Digital Marketing ,Android Mobile Apps Development

Post Slider (Homepage)

Blog Archive

Malwares

Transfer Files

Media Players

Download Manager

Window

Torrents Soft

Developer Tools

Botton Ad

Ads

Newsletter

 

© 2013 PHP TRAINING IN MUMBAI BY OM SIR . All rights resevered. Designed by OM SIR

Back To Top