Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

How to Import and Export CSV Files Using PHP and MySQL

How to Import and Export CSV Files Using PHP and MySQL


Hi Today discussed PHP Server side Scripting Language How to Import and Export CSV Files using PHP and mysql. Database normally insert and update and delete queries and bulk insert it's means csv file same column file data csv file data insert mysql. code follows.


How to Import and Export CSV Files Using PHP and MySQL
How to Import and Export CSV Files Using PHP and MySQL



First Create database and then create table.

CREATE DATABASE employee
Create table

CREATE TABLE employeedetils(
eid VARCHAR(50) UNSIGNED PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
create_date VARCHAR(50)
)
dbconnect

<?php
function getdb(){
$servername = "localhost";
$username = "root";
$password = "";
$db = "employee";

try {
   
    $conn = mysqli_connect($servername, $username, $password, $db);
     //echo "Connected successfully"; 
    }
catch(exception $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }
    return $conn;
}
?>
PHP File Import function phpfiles.php

<?php


 if(isset($_POST["Import"])){
  
  $filename=$_FILES["file"]["tmp_name"];  


   if($_FILES["file"]["size"] > 0)
   {
     $file = fopen($filename, "r");
         while (($getData = fgetcsv($file, 10000, ",")) !== FALSE)
          {


            $sql = "INSERT into employeedetils(eid,firstname,lastname,email,create_date)                    values ('".$getData[0]."','".$getData[1]."','".$getData[2]."','".$getData[3]."','".$getData[4]."')";
                   $result = mysqli_query($con, $sql);
    if(!isset($result))
    {
     echo "<script type=\"text/javascript\">
       alert(\"Invalid File:Please Upload CSV File.\");
       window.location = \"index.php\"
        </script>";  
    }
    else {
       echo "<script type=\"text/javascript\">
      alert(\"CSV File has been successfully Imported.\");
      window.location = \"index.php\"
     </script>";
    }
          }
   
          fclose($file); 
   }
 }  


 ?>

View Page design bootstrap lib include

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" crossorigin="anonymous"></script>
View Page


<!DOCTYPE html>
<html lang="en">

<head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" crossorigin="anonymous">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" crossorigin="anonymous">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" crossorigin="anonymous"></script>

</head>

<body>
    <div id="wrap">
        <div class="container">
            <div class="row">

                <form class="form-horizontal" action="phpfiles.php" method="post" name="upload_excel" enctype="multipart/form-data">
                    <fieldset>

                        <!-- Form Name -->
                        <legend>Form Name</legend>

                        <!-- File Button -->
                        <div class="form-group">
                            <label class="col-md-4 control-label" for="filebutton">Select File</label>
                            <div class="col-md-4">
                                <input type="file" name="file" id="file" class="input-large">
                            </div>
                        </div>

                        <!-- Button -->
                        <div class="form-group">
                            <label class="col-md-4 control-label" for="singlebutton">Import data</label>
                            <div class="col-md-4">
                                <button type="submit" id="submit" name="Import" class="btn btn-primary button-loading" data-loading-text="Loading...">Import</button>
                            </div>
                        </div>

                    </fieldset>
                </form>

            </div>
            <?php
               getdbrecords();
            ?>
        </div>
    </div>
</body>

</html>
view php records

function getdbrecords(){
    $con = getdb();
    $Sql = "SELECT * FROM employeedetils";
    $result = mysqli_query($con, $Sql);  


    if (mysqli_num_rows($result) > 0) {
     echo "<div class='table-responsive'><table id='myTable' class='table table-striped table-bordered'>
             <thead><tr><th>EMP ID</th>
                          <th>First Name</th>
                          <th>Last Name</th>
                          <th>Email</th>
                          <th>Registration Date</th>
                        </tr></thead><tbody>";


     while($row = mysqli_fetch_assoc($result)) {

         echo "<tr><td>" . $row['eid']."</td>
                   <td>" . $row['firstname']."</td>
                   <td>" . $row['lastname']."</td>
                   <td>" . $row['email']."</td>
                   <td>" . $row['create_date']."</td></tr>";        
     }
    
     echo "</tbody></table></div>";
     
} else {
     echo "you have no records";
}
}

Export MySQL to CSV With PHP

<div>
            <form class="form-horizontal" action="phpfiles.php" method="post" name="upload_excel"   
                      enctype="multipart/form-data">
                  <div class="form-group">
                            <div class="col-md-4 col-md-offset-4">
                                <input type="submit" name="Export" class="btn btn-success" value="export to excel"/>
                            </div>
                   </div>                    
            </form>           
 </div>
Export Functions

if(isset($_POST["Export"])){
   
      header('Content-Type: text/csv; charset=utf-8');  
      header('Content-Disposition: attachment; filename=data.csv');  
      $output = fopen("php://output", "w");  
      fputcsv($output, array('ID', 'First Name', 'Last Name', 'Email', 'Joining Date'));  
      $query = "SELECT * from employeedetils ORDER BY emp_id DESC";  
      $result = mysqli_query($con, $query);  
      while($row = mysqli_fetch_assoc($result))  
      {  
           fputcsv($output, $row);  
      }  
      fclose($output);  
 }  

List of Timezone GMT Database Query Mysql

List of Timezone GMT Database Query Mysql

Hi Today Discussed List of Timezone GMT Database Query Mysql normally php mysql basic database country timezone and state city this basic normally database stored so timezone database followes queries.

List of Timezone GMT Database Query Mysql
List of Timezone GMT Database Query Mysql

CREATE TABLE `zone` (
  `id` int(11) NOT NULL,
  `country_code` varchar(255) NOT NULL,
  `zone_name` text NOT NULL,
  `status` int(11) NOT NULL COMMENT '0-inactive 1-active'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Database Value


INSERT INTO `zone` (`id`, `country_code`, `zone_name`, `status`) VALUES
(1, 'Pacific/Kwajalein', '(GMT -12:00) Eniwetok, Kwajalein', 0),
(2, 'Pacific/Samoa', '(GMT -11:00) Midway Island, Samoa', 0),
(3, 'Pacific/Honolulu', '(GMT -10:00) Hawaii', 0),
(4, 'America/Anchorage', '(GMT -9:00) Alaska', 0),
(5, 'America/Los_Angeles', '(GMT -8:00) Pacific Time (US & Canada) Los Angeles, Seattle', 0),
(6, 'America/Denver', '(GMT -7:00) Mountain Time (US & Canada) Denver', 0),
(7, 'America/Chicago', '(GMT -6:00) Central Time (US & Canada), Chicago, Mexico City', 0),
(8, 'America/New_York', '(GMT -5:00) Eastern Time (US & Canada), New York, Bogota, Lima', 0),
(9, 'Atlantic/Bermuda', '(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz', 0),
(10, 'Canada/Newfoundland', '(GMT -3:30) Newfoundland', 0),
(11, 'Brazil/East', '(GMT -3:00) Brazil, Buenos Aires, Georgetown', 0),
(12, 'Atlantic/Azores', '(GMT -2:00) Mid-Atlantic', 0),
(13, 'Atlantic/Cape_Verde', '(GMT -1:00 hour) Azores, Cape Verde Islands', 0),
(14, 'Europe/London', '(GMT) Western Europe Time, London, Lisbon, Casablanca', 0),
(15, 'Europe/Brussels', '(GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris', 0),
(16, 'Europe/Helsinki', '(GMT +2:00) Kaliningrad, South Africa', 0),
(17, 'Asia/Baghdad', '(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg', 0),
(18, 'Asia/Tehran', '(GMT +3:30) Tehran', 0),
(19, 'Asia/Baku', '(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi', 0),
(20, 'Asia/Kabul', '(GMT +4:30) Kabul', 0),
(21, 'Asia/Karachi', '(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent', 1),
(22, 'Asia/Calcutta', '(GMT +5:30) Bombay, Calcutta, Madras, New Delhi', 0),
(23, 'Asia/Dhaka', '(GMT +6:00) Almaty, Dhaka, Colombo', 0),
(24, 'Asia/Bangkok', '(GMT +7:00) Bangkok, Hanoi, Jakarta', 0),
(25, 'Asia/Hong_Kong', '(GMT +8:00) Beijing, Perth, Singapore, Hong Kong', 0),
(26, 'Asia/Tokyo', '(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk', 0),
(27, 'Australia/Adelaide', '(GMT +9:30) Adelaide, Darwin', 0),
(28, 'Pacific/Guam', '(GMT +10:00) Eastern Australia, Guam, Vladivostok', 0),
(29, 'Asia/Magadan', '(GMT +11:00) Magadan, Solomon Islands, New Caledonia', 0),
(30, 'Pacific/Fiji', '(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka', 0);

Country And Currency Database

Currency Database

Hi Today discussed Country And Currency Database mysql database basic database country currency symbol and separator database followus code.

Country And Currency Database
Country And Currency Database


CREATE TABLE IF NOT EXISTS `currencies` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `country` varchar(100) DEFAULT NULL,
  `currency` varchar(100) DEFAULT NULL,
  `code` varchar(25) DEFAULT NULL,
  `symbol` varchar(25) DEFAULT NULL,
  `thousand_separator` varchar(10) DEFAULT NULL,
  `decimal_separator` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=132 DEFAULT CHARSET=utf8;

-- Dumping data for table invoice_new.currencies: 131 rows
/*!40000 ALTER TABLE `currencies` DISABLE KEYS */;
INSERT INTO `currencies` (`id`, `country`, `currency`, `code`, `symbol`, 
`thousand_separator`, `decimal_separator`) VALUES
 (1, 'Albania', 'Leke', 'ALL', 'Lek', ',', '.'),
 (2, 'America', 'Dollars', 'USD', '$', ',', '.'),
 (3, 'Afghanistan', 'Afghanis', 'AF', '؋', ',', '.'),
 (4, 'Argentina', 'Pesos', 'ARS', '$', ',', '.'),
 (5, 'Aruba', 'Guilders', 'AWG', 'ƒ', ',', '.'),
 (6, 'Australia', 'Dollars', 'AUD', '$', ',', '.'),
 (7, 'Azerbaijan', 'New Manats', 'AZ', 'ман', ',', '.'),
 (8, 'Bahamas', 'Dollars', 'BSD', '$', ',', '.'),
 (9, 'Barbados', 'Dollars', 'BBD', '$', ',', '.'),
 (10, 'Belarus', 'Rubles', 'BYR', 'p.', ',', '.'),
 (11, 'Belgium', 'Euro', 'EUR', '€', ',', '.'),
 (12, 'Beliz', 'Dollars', 'BZD', 'BZ$', ',', '.'),
 (13, 'Bermuda', 'Dollars', 'BMD', '$', ',', '.'),
 (14, 'Bolivia', 'Bolivianos', 'BOB', '$b', ',', '.'),
 (15, 'Bosnia and Herzegovina', 'Convertible Marka', 'BAM', 'KM', ',', '.'),
 (16, 'Botswana', 'Pula\'s', 'BWP', 'P', ',', '.'),
 (17, 'Bulgaria', 'Leva', 'BG', 'лв', ',', '.'),
 (18, 'Brazil', 'Reais', 'BRL', 'R$', ',', '.'),
 (19, 'Britain (United Kingdom)', 'Pounds', 'GBP', '£', ',', '.'),
 (20, 'Brunei Darussalam', 'Dollars', 'BND', '$', ',', '.'),
 (21, 'Cambodia', 'Riels', 'KHR', '៛', ',', '.'),
 (22, 'Canada', 'Dollars', 'CAD', '$', ',', '.'),
 (23, 'Cayman Islands', 'Dollars', 'KYD', '$', ',', '.'),
 (24, 'Chile', 'Pesos', 'CLP', '$', ',', '.'),
 (25, 'China', 'Yuan Renminbi', 'CNY', '¥', ',', '.'),
 (26, 'Colombia', 'Pesos', 'COP', '$', ',', '.'),
 (27, 'Costa Rica', 'Colón', 'CRC', '₡', ',', '.'),
 (28, 'Croatia', 'Kuna', 'HRK', 'kn', ',', '.'),
 (29, 'Cuba', 'Pesos', 'CUP', '₱', ',', '.'),
 (30, 'Cyprus', 'Euro', 'EUR', '€', ',', '.'),
 (31, 'Czech Republic', 'Koruny', 'CZK', 'Kč', ',', '.'),
 (32, 'Denmark', 'Kroner', 'DKK', 'kr', ',', '.'),
 (33, 'Dominican Republic', 'Pesos', 'DOP ', 'RD$', ',', '.'),
 (34, 'East Caribbean', 'Dollars', 'XCD', '$', ',', '.'),
 (35, 'Egypt', 'Pounds', 'EGP', '£', ',', '.'),
 (36, 'El Salvador', 'Colones', 'SVC', '$', ',', '.'),
 (37, 'England (United Kingdom)', 'Pounds', 'GBP', '£', ',', '.'),
 (38, 'Euro', 'Euro', 'EUR', '€', ',', '.'),
 (39, 'Falkland Islands', 'Pounds', 'FKP', '£', ',', '.'),
 (40, 'Fiji', 'Dollars', 'FJD', '$', ',', '.'),
 (41, 'France', 'Euro', 'EUR', '€', ',', '.'),
 (42, 'Ghana', 'Cedis', 'GHC', '¢', ',', '.'),
 (43, 'Gibraltar', 'Pounds', 'GIP', '£', ',', '.'),
 (44, 'Greece', 'Euro', 'EUR', '€', ',', '.'),
 (45, 'Guatemala', 'Quetzales', 'GTQ', 'Q', ',', '.'),
 (46, 'Guernsey', 'Pounds', 'GGP', '£', ',', '.'),
 (47, 'Guyana', 'Dollars', 'GYD', '$', ',', '.'),
 (48, 'Holland (Netherlands)', 'Euro', 'EUR', '€', ',', '.'),
 (49, 'Honduras', 'Lempiras', 'HNL', 'L', ',', '.'),
 (50, 'Hong Kong', 'Dollars', 'HKD', '$', ',', '.'),
 (51, 'Hungary', 'Forint', 'HUF', 'Ft', ',', '.'),
 (52, 'Iceland', 'Kronur', 'ISK', 'kr', ',', '.'),
 (53, 'India', 'Rupees', 'INR', 'Rp', ',', '.'),
 (54, 'Indonesia', 'Rupiahs', 'IDR', 'Rp', ',', '.'),
 (55, 'Iran', 'Rials', 'IRR', '﷼', ',', '.'),
 (56, 'Ireland', 'Euro', 'EUR', '€', ',', '.'),
 (57, 'Isle of Man', 'Pounds', 'IMP', '£', ',', '.'),
 (58, 'Israel', 'New Shekels', 'ILS', '₪', ',', '.'),
 (59, 'Italy', 'Euro', 'EUR', '€', ',', '.'),
 (60, 'Jamaica', 'Dollars', 'JMD', 'J$', ',', '.'),
 (61, 'Japan', 'Yen', 'JPY', '¥', ',', '.'),
 (62, 'Jersey', 'Pounds', 'JEP', '£', ',', '.'),
 (63, 'Kazakhstan', 'Tenge', 'KZT', 'лв', ',', '.'),
 (64, 'Korea (North)', 'Won', 'KPW', '₩', ',', '.'),
 (65, 'Korea (South)', 'Won', 'KRW', '₩', ',', '.'),
 (66, 'Kyrgyzstan', 'Soms', 'KGS', 'лв', ',', '.'),
 (67, 'Laos', 'Kips', 'LAK', '₭', ',', '.'),
 (68, 'Latvia', 'Lati', 'LVL', 'Ls', ',', '.'),
 (69, 'Lebanon', 'Pounds', 'LBP', '£', ',', '.'),
 (70, 'Liberia', 'Dollars', 'LRD', '$', ',', '.'),
 (71, 'Liechtenstein', 'Switzerland Francs', 'CHF', 'CHF', ',', '.'),
 (72, 'Lithuania', 'Litai', 'LTL', 'Lt', ',', '.'),
 (73, 'Luxembourg', 'Euro', 'EUR', '€', ',', '.'),
 (74, 'Macedonia', 'Denars', 'MKD', 'ден', ',', '.'),
 (75, 'Malaysia', 'Ringgits', 'MYR', 'RM', ',', '.'),
 (76, 'Malta', 'Euro', 'EUR', '€', ',', '.'),
 (77, 'Mauritius', 'Rupees', 'MUR', '₨', ',', '.'),
 (78, 'Mexico', 'Pesos', 'MX', '$', ',', '.'),
 (79, 'Mongolia', 'Tugriks', 'MNT', '₮', ',', '.'),
 (80, 'Mozambique', 'Meticais', 'MZ', 'MT', ',', '.'),
 (81, 'Namibia', 'Dollars', 'NAD', '$', ',', '.'),
 (82, 'Nepal', 'Rupees', 'NPR', '₨', ',', '.'),
 (83, 'Netherlands Antilles', 'Guilders', 'ANG', 'ƒ', ',', '.'),
 (84, 'Netherlands', 'Euro', 'EUR', '€', ',', '.'),
 (85, 'New Zealand', 'Dollars', 'NZD', '$', ',', '.'),
 (86, 'Nicaragua', 'Cordobas', 'NIO', 'C$', ',', '.'),
 (87, 'Nigeria', 'Nairas', 'NG', '₦', ',', '.'),
 (88, 'North Korea', 'Won', 'KPW', '₩', ',', '.'),
 (89, 'Norway', 'Krone', 'NOK', 'kr', ',', '.'),
 (90, 'Oman', 'Rials', 'OMR', '﷼', ',', '.'),
 (91, 'Pakistan', 'Rupees', 'PKR', '₨', ',', '.'),
 (92, 'Panama', 'Balboa', 'PAB', 'B/.', ',', '.'),
 (93, 'Paraguay', 'Guarani', 'PYG', 'Gs', ',', '.'),
 (94, 'Peru', 'Nuevos Soles', 'PE', 'S/.', ',', '.'),
 (95, 'Philippines', 'Pesos', 'PHP', 'Php', ',', '.'),
 (96, 'Poland', 'Zlotych', 'PL', 'zł', ',', '.'),
 (97, 'Qatar', 'Rials', 'QAR', '﷼', ',', '.'),
 (98, 'Romania', 'New Lei', 'RO', 'lei', ',', '.'),
 (99, 'Russia', 'Rubles', 'RUB', 'руб', ',', '.'),
 (100, 'Saint Helena', 'Pounds', 'SHP', '£', ',', '.'),
 (101, 'Saudi Arabia', 'Riyals', 'SAR', '﷼', ',', '.'),
 (102, 'Serbia', 'Dinars', 'RSD', 'Дин.', ',', '.'),
 (103, 'Seychelles', 'Rupees', 'SCR', '₨', ',', '.'),
 (104, 'Singapore', 'Dollars', 'SGD', '$', ',', '.'),
 (105, 'Slovenia', 'Euro', 'EUR', '€', ',', '.'),
 (106, 'Solomon Islands', 'Dollars', 'SBD', '$', ',', '.'),
 (107, 'Somalia', 'Shillings', 'SOS', 'S', ',', '.'),
 (108, 'South Africa', 'Rand', 'ZAR', 'R', ',', '.'),
 (109, 'South Korea', 'Won', 'KRW', '₩', ',', '.'),
 (110, 'Spain', 'Euro', 'EUR', '€', ',', '.'),
 (111, 'Sri Lanka', 'Rupees', 'LKR', '₨', ',', '.'),
 (112, 'Sweden', 'Kronor', 'SEK', 'kr', ',', '.'),
 (113, 'Switzerland', 'Francs', 'CHF', 'CHF', ',', '.'),
 (114, 'Suriname', 'Dollars', 'SRD', '$', ',', '.'),
 (115, 'Syria', 'Pounds', 'SYP', '£', ',', '.'),
 (116, 'Taiwan', 'New Dollars', 'TWD', 'NT$', ',', '.'),
 (117, 'Thailand', 'Baht', 'THB', '฿', ',', '.'),
 (118, 'Trinidad and Tobago', 'Dollars', 'TTD', 'TT$', ',', '.'),
 (119, 'Turkey', 'Lira', 'TRY', 'TL', ',', '.'),
 (120, 'Turkey', 'Liras', 'TRL', '£', ',', '.'),
 (121, 'Tuvalu', 'Dollars', 'TVD', '$', ',', '.'),
 (122, 'Ukraine', 'Hryvnia', 'UAH', '₴', ',', '.'),
 (123, 'United Kingdom', 'Pounds', 'GBP', '£', ',', '.'),
 (124, 'United States of America', 'Dollars', 'USD', '$', ',', '.'),
 (125, 'Uruguay', 'Pesos', 'UYU', '$U', ',', '.'),
 (126, 'Uzbekistan', 'Sums', 'UZS', 'лв', ',', '.'),
 (127, 'Vatican City', 'Euro', 'EUR', '€', ',', '.'),
 (128, 'Venezuela', 'Bolivares Fuertes', 'VEF', 'Bs', ',', '.'),
 (129, 'Vietnam', 'Dong', 'VND', '₫', ',', '.'),
 (130, 'Yemen', 'Rials', 'YER', '﷼', ',', '.'),
 (131, 'Zimbabwe', 'Zimbabwe Dollars', 'ZWD', 'Z$', ',', '.');

Insert,Update,Delete PHP Using Ajax

Insert,Update,Delete PHP Using Ajax 


Hi Today Discussed Core PHP Insert,Update,Delete php using Ajax, Php insert view update delete without loading browser so data pasing ajax follows code.

Insert,Update,Delete PHP Using Ajax
Insert,Update,Delete PHP Using Ajax 

sql

CREATE TABLE IF NOT EXISTS `user_detail` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` text NOT NULL,
  `age` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

list.php

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript" src="modify.js"></script>
</head>
<body>
<div id="wrapper">

<?php
$host="localhost";
$username="root";
$password="";
$databasename="ajaxphp";
$connect=mysql_connect($host,$username,$password);
$db=mysql_select_db($databasename);

$select =mysql_query("SELECT * FROM user_detail");
?>

<table align="center" cellpadding="10" border="1" id="user_table">
<tr>
<th>NAME</th>
<th>AGE</th>
<th></th>
</tr>
<?php
while ($row=mysql_fetch_array($select)) 
{
 ?>
 <tr id="row<?php echo $row['id'];?>">
  <td id="name_val<?php echo $row['id'];?>"><?php echo $row['name'];?></td>
  <td id="age_val<?php echo $row['id'];?>"><?php echo $row['age'];?></td>
  <td>
   <input type='button' class="edit_button" id="edit_button<?php echo $row['id'];?>" value="edit" onclick="edit_row('<?php echo $row['id'];?>');">
   <input type='button' class="save_button" id="save_button<?php echo $row['id'];?>" value="save" onclick="save_row('<?php echo $row['id'];?>');">
   <input type='button' class="delete_button" id="delete_button<?php echo $row['id'];?>" value="delete" onclick="delete_row('<?php echo $row['id'];?>');">
  </td>
 </tr>
 <?php
}
?>

<tr id="new_row">
 <td><input type="text" id="new_name"></td>
 <td><input type="text" id="new_age"></td>
 <td><input type="button" value="Insert Row" onclick="insert_row();"></td>
</tr>
</table>

</div>
</body>
</html>
modify.js

function edit_row(id)
{
 var name=document.getElementById("name_val"+id).innerHTML;
 var age=document.getElementById("age_val"+id).innerHTML;

 document.getElementById("name_val"+id).innerHTML="<input type='text' id='name_text"+id+"' value='"+name+"'>";
 document.getElementById("age_val"+id).innerHTML="<input type='text' id='age_text"+id+"' value='"+age+"'>";
 
 document.getElementById("edit_button"+id).style.display="none";
 document.getElementById("save_button"+id).style.display="block";
}

function save_row(id)
{
 var name=document.getElementById("name_text"+id).value;
 var age=document.getElementById("age_text"+id).value;
 
 $.ajax
 ({
  type:'post',
  url:'modify_records.php',
  data:{
   edit_row:'edit_row',
   row_id:id,
   name_val:name,
   age_val:age
  },
  success:function(response) {
   if(response=="success")
   {
    document.getElementById("name_val"+id).innerHTML=name;
    document.getElementById("age_val"+id).innerHTML=age;
    document.getElementById("edit_button"+id).style.display="block";
    document.getElementById("save_button"+id).style.display="none";
   }
  }
 });
}

function delete_row(id)
{
 $.ajax
 ({
  type:'post',
  url:'modify_records.php',
  data:{
   delete_row:'delete_row',
   row_id:id,
  },
  success:function(response) {
   if(response=="success")
   {
    var row=document.getElementById("row"+id);
    row.parentNode.removeChild(row);
   }
  }
 });
}

function insert_row()
{
 var name=document.getElementById("new_name").value;
 var age=document.getElementById("new_age").value;

 $.ajax
 ({
  type:'post',
  url:'modify_records.php',
  data:{
   insert_row:'insert_row',
   name_val:name,
   age_val:age
  },
  success:function(response) {
   if(response!="")
   {
    var id=response;
    var table=document.getElementById("user_table");
    var table_len=(table.rows.length)-1;
    var row = table.insertRow(table_len).outerHTML="<tr id='row"+id+"'><td id='name_val"+id+"'>"+name+"</td><td id='age_val"+id+"'>"+age+"</td><td><input type='button' class='edit_button' id='edit_button"+id+"' value='edit' onclick='edit_row("+id+");'/><input type='button' class='save_button' id='save_button"+id+"' value='save' onclick='save_row("+id+");'/><input type='button' class='delete_button' id='delete_button"+id+"' value='delete' onclick='delete_row("+id+");'/></td></tr>";

    document.getElementById("new_name").value="";
    document.getElementById("new_age").value="";
   }
  }
 });
}
modify_record.php

<?php
$host="localhost";
$username="root";
$password="";
$databasename="ajaxphp";

$connect=mysql_connect($host,$username,$password);
$db=mysql_select_db($databasename);

if(isset($_POST['edit_row']))
{
 $row=$_POST['row_id'];
 $name=$_POST['name_val'];
 $age=$_POST['age_val'];

 mysql_query("update user_detail set name='$name',age='$age' where id='$row'");
 echo "success";
 exit();
}

if(isset($_POST['delete_row']))
{
 $row_no=$_POST['row_id'];
 mysql_query("delete from user_detail where id='$row_no'");
 echo "success";
 exit();
}

if(isset($_POST['insert_row']))
{
 $name=$_POST['name_val'];
 $age=$_POST['age_val'];
 mysql_query("insert into user_detail values('','$name','$age')");
 echo mysql_insert_id();
 exit();
}
?>

Automatically create cache file with php And Quickly Loaded in PHP Files

Automatically create cache file with php And Quickly Loaded in PHP Files


Hi Today Discussed Automatically create cache file with php and Quickly loaded in php files large number of data in mysql database is once run this file the data automatically create cache file and then quickly loaded this file follows briefly discussed.

Automatically create cache file with php And Quickly Loaded in PHP Files
Automatically create cache file with php And Quickly Loaded in PHP Files

Your php file quick load speed  increased your web site each every page loaded auto created cache file follows code.

<?php
function getUrl () {
    if (!isset($_SERVER['REQUEST_URI'])) {
    $url = $_SERVER['REQUEST_URI'];
    } else {
    $url = $_SERVER['SCRIPT_NAME'];
    $url .= (!empty($_SERVER['QUERY_STRING']))? '?' . $_SERVER[ 'QUERY_STRING' ] : '';

    }
    return $url;
}

//getUrl gets the queried page with query string
function cache ($buffer) { //page's content is $buffer
    $url = getUrl();
    $filename = md5($url) . '.cache';
    $data = time() . '¦' . $buffer;
    $filew = fopen("cache/" . $filename, 'w');
    fwrite($filew, $data);
    fclose($filew);
    return $buffer;
}

function display () {
    $url = getUrl();
    $filename = md5($url) . '.cache';
    if (!file_exists("/cache/" . $filename)) {
    return false;
    }
    $filer = fopen("cache/" . $filename, 'r');
    $data = fread($filer, filesize("cache/" . $filename));
    fclose($filer);
    $content = explode('¦', $data, 2);
    if (count($content)!= 2 OR !is_numeric($content['0'])) {
        return false;
    }
    if (time()-(100) > $content['0']) { // 100 is the cache time here!!!
        return false;
    }
        echo $content['1'];
        die();
}

// Display cache (if any)
display();  // if it is displayed, die function will end the program here.

// if no cache, callback cache
ob_start ('cache');
?>

PHP Execute a HTTP POST Using PHP CURL

PHP Execute a HTTP POST Using PHP CURL

Today Discussed PHP Curl Post Means PHP Execute a HTTP POST Using PHP Curl.Well, there's a hurdle -- the information isn't going to be saved on the localhost database -- it needs to be stored in a remote database that I cannot connect directly to.

PHP Execute a HTTP POST Using PHP CURL
PHP Execute a HTTP POST Using PHP CURL

  1. User will submit the form, as usual.
  2. In the form processing PHP, I use cURL to execute a POST transmission to a PHP script on the customer's server.
  3. The remote script would do a MySQL INSERT query into the customer's private database.
This solution worked quite well so I thought I'd share it with you. Here's how you execute a POST using the PHP CURL library.


Curl Post Code Follows

//extract data from the post
//set POST variables
$url = 'http://domain.com/get-post.php';
$fields = array(
 'lname' => urlencode($_POST['last_name']),
 'fname' => urlencode($_POST['first_name']),
 'title' => urlencode($_POST['title']),
 
);

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

Abstract Classes and Interface in PHP

Abstract Classes and Interface in PHP

Today we discussed Abstract Classes and Interface in PHP Data abstraction first what is abstraction. As from name it seem like something that is hidden.  Yes nature of the abstract classes are same.Abstract classes are those classes which can not be directly initialized. Or in other word we can say that you can not create object of abstract classes.

Abstract Classes and Interface in PHP
Abstract Classes and Interface in PHP
  1. What is abstract classes.
  2. What is interface
  3. How to implement abstract classes in php
  4. How to implement interface in php
  5. Different between abstract classes and interface.
What is abstract Classes

 Abstract classes always created for inheritance purpose. You can only inherit abstract class in your child class. Lots of people say that in abstract class at least your one method should be abstract. Abstract method are the method which is only defined but declared. This is not true definition as per my assumption. But your any class has at least one method abstract than your class is abstract class.Usually abstract class are also known as base class. We call it base class because abstract class are not the class which is available directly for creating object. It can only act as parent class of any normal class. You can use abstract class in class hierarchy. Mean one abstract class can inherit another abstract class also.



Abstract classes in PHP

Abstract Classes and Interface in PHP
Abstract Classes and Interface in PHP

Abstract classes in php are simillar like other oop languages. You can create abstract classes in php using abstract keyword. Once you will make any class abstract in php you can not create object of that class.



abstract class abc
{
public function xyz()
{
return 1;
}
}
$a = new abc();//this will throw error in php
abstract class testParent
{
public function abc()
{
//body of your funciton
}
}
class testChild extends testParent
{
public function xyz()
{
//body of your function
}
}
$a = new testChild();



Implementation of abstract method



abstract class abc

{

abstract protected function f1($a , $b);

}

class xyz extends abc

{

protected function f1($name , $address)

{

echo "$name , $address";

}

}

$a = new xyz();
abstract class parentTest
{
abstract protected function f1();
abstract public function f2();
//abstract private function f3(); //this will trhow error
}
class childTest
{
public function f1()
{
//body of your function
}
public function f2()
{
//body of your function
}
protected function f3()
{
//body of your function
}
}
$a = new childTest();








PHP database while loop value alphabetically view

PHP database while loop value alphabetically view


PHP database while loop value alphabetically view
PHP database while loop value alphabetically view

Today Discussed PHP database while loop value alphabetical Order view how to display this task is view looks nice view and order based view a database value flows this code.

mysql queris: 

$query = "SELECT `primaryid`,`fieldname`,LEFT(`fieldname`, 1) AS `first_char` FROM tbl_name WHERE (UPPER(`fieldname`) BETWEEN 'A' AND 'Z' OR `fieldname` BETWEEN '0' AND '9') ORDER BY `fieldname`"
$queryresult = mysql_query($query);                                          $current_char = '';
                                                                           while ($row = mysql_fetch_assoc($queryresult)) {                       if ($row['first_char'] != $current_char) {
                        $current_char = $row['first_char'];

                        echo '<div class="clearfix"></div><h1>' . strtoupper($current_char) . '</h1>' . '<br />-----<br />';
                    }                                                     <?php echo stripslashes($row['fieldname']); } ?>
Copy and Paste this code this code is example modify queriys field name is your database table current fieldname and tbl_name is your database table name just replace this field. and another part of code is whill loop displaying looping function try this code and more example click here

PHP Image delete Common Function Jquery Ajax Call

PHP Image delete Common Function Jquery Ajax Call


Today Discussed PHP Image delete Common Function Jquery Ajax Call Normal Core PHP Commonly Write one function just put table name and primary id and path get delete the image and unlink this page follows code.

PHP Image delete Common Function Jquery Ajax Call
PHP Image delete Common Function Jquery Ajax Call


Form.php

 <div class="col-md-6" id="delimage">
                                    <label> </label>
                                    <?php if (getprofile('image', $_SESSION['UID']) != '') { ?>
                                                                                        <img src="<?php echo $sitename . 'pages/profile/image/' . getprofile('image', $_SESSION['UID']); ?>" style="padding-bottom:10px;" height="100" /><!--&nbsp;<buttton type="button" style="cursor:pointer;" class="btn btn-danger" name="del" id="del" onclick="javascript:dellocationimage();"><i class="fa fa-close">&nbsp;Delete Image</i></buttton>-->
                                        <button type="button" style="cursor:pointer;" class="btn btn-danger" name="del" id="del" onclick="javascript:deleteimage('<?php echo getprofile('image', $_SESSION['UID']); ?>', '<?php echo $_SESSION['UID']; ?>', 'manageprofile', '../pages/profile/image/', 'image', 'pid');"><i class="fa fa-close">&nbsp;Delete Image</i></button>
                                    <?php } ?>
                                </div>
Ajax.js(Javascript)
function deleteimage(a, b, c, d, e, f)
{
    if (window.XMLHttpRequest)
    {
        oRequestsubcat = new XMLHttpRequest();
    } else if (window.ActiveXObject)
    {
        oRequestsubcat = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (a != '' && b != '' && c != '' && d !='' && e !=''&& f !='')
    {
        document.getElementById("delimage").innerHTML = '<div class="overlay"><i class="fa fa-refresh fa-spin"></i></div>';
        oRequestsubcat.open("POST", Settings.base_url + "config/functions_ajax.php", true);
        oRequestsubcat.onreadystatechange = delimg;
        oRequestsubcat.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        oRequestsubcat.send("image=" + a + "&id=" + b + "&table=" +c + "&path=" + d + "&images=" +e + "&pid=" + f);
        console.log(a,b,c,d,e,f);
    }
}
function delimg()
{
    if (oRequestsubcat.readyState == 4)
    {
        if (oRequestsubcat.status == 200)
        {
            document.getElementById("delimage").innerHTML = oRequestsubcat.responseText;
        }
        else
        {
            document.getElementById("delimage").innerHTML = oRequestsubcat.responseText;
        }
    }
}
or

Ajax.js(Jquery)
function deleteimage(a,b,c,d)
{
    $.post(Settings.base_url + "config/functions_ajax.php",{ a:a,b:b,c:c,d:d },function(data){
        console.log(data);
        $('#delimage').html(data);
        //alert(data);
    });
}

Function.php

if (($_REQUEST['image'] != '') && ($_REQUEST['id'] != '') && ($_REQUEST['table'] != '')&& ($_REQUEST['path'] != '')&& ($_REQUEST['images'] != '')&& ($_REQUEST['pid'] != '')) {
    unlink($_REQUEST['path'].$_REQUEST['image']);
 // $s = "UPDATE `".$_REQUEST['table']."` SET `".$_REQUEST['images']."`='' WHERE `".$_REQUEST['pid']."`='" . $_REQUEST['id'] . "'";
   // echo $s;
    //return $s;
   // exit;
    DB("UPDATE `".$_REQUEST['table']."` SET `".$_REQUEST['images']."`='' WHERE `pid`='" . $_REQUEST['id'] . "'");
    DB("INSERT `history` (`page`,`pageid`,`action`,`userid`,`ip`,`actionid`,`info`) VALUES ('Manage Profile','9','Delete','" . $_SESSION['UID'] . "','" . $_SERVER['REMOTE_ADDR'] . "','" . $_REQUEST['b'] . "','Image Deletion')");
  echo '<div class="alert alert-danger alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-close"></i>Succesfully Deleted</h4><!--<a href="' . $sitename . 'settings/adddepartment.htm">Add another one</a>--></div>';

PHP Security ImagesCaptcha

PHP security imagesCaptcha

PHP Security imagesCaptcha is a simple test to determine if a user is a computer or a human.  It is used to prevent spam abuse on the websites. Just Avoid spamers and crackers in the sites. So if you use CAPTCHA on your web forms, this can help in stopping some bots and making life harder for other bots in accessing or using your forms. Normal Core PHP simple Shopping Cart

PHP security imagesCaptcha
PHP security imagesCaptcha


Captcha.php

<?php
session_start();
class CaptchaSecurityImages {

 var $font = 'monofont.ttf';

 function generateCode($characters) {
  /* list all possible characters, similar looking characters and vowels have been removed */
  $possible = '23456789bcdfghjkmnpqrstvwxyz';
  $code = '';
  $i = 0;
  while ($i < $characters) { 
   $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
   $i++;
  }
  return $code;
 }

 function CaptchaSecurityImages($width='60',$height='50',$characters='5') {
  $code = $this->generateCode($characters);
  /* font size will be 75% of the image height */
  $font_size = $height * 0.85;
  $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
  /* set the colours */
  $background_color = imagecolorallocate($image, 255, 255, 255);
  $text_color = imagecolorallocate($image, 20, 40, 100);
  $noise_color = imagecolorallocate($image, 200, 200, 200);
  /* generate random dots in background */
  for( $i=0; $i<($width*$height)/3; $i++ ) {
   imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
  }
  /* generate random lines in background */
  for( $i=0; $i<($width*$height)/150; $i++ ) {
   imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
  }
  /* create textbox and add text */
  $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
  $x = ($width - $textbox[4])/2;
  $y = ($height - $textbox[5])/2;
  imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
  /* output captcha image to browser */
  header('Content-Type: image/jpeg');
  imagejpeg($image);
  imagedestroy($image);
  $_SESSION['keycode'] = $code;
 }

}

$width = isset($_GET['width']) ? $_GET['width'] : '90';
$height = isset($_GET['height']) ? $_GET['height'] : '21';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '5';

$captcha = new CaptchaSecurityImages($width,$height,$characters);

?>
Your Form Page Added Following Script.
<script type="text/javascript">

function refreshCaptcha(abspath){

document.getElementById('refcaptimg').src="Captcha.php?t=" + new Date().getTime();

}</script>
Form

<form name="frmContact" method="post" action="contact-us.html">
<table width="175" border="0" cellpadding="2" cellspacing="0">
 <tr>
   <td  height="81" align="left" valign="middle"><a href="full_certificate.pdf" target="_blank"><img src="images/svc.gif" alt="" border="0"/></a></td>

  </tr>
<tr>

<td style="padding-bottom:10px;">
<div>
<!-- End Comm100 Live Chat Button Code -->

</td>
  </tr>

  <tr>
    <td class="page_heading"> </td>
  </tr>
  <tr>

   <td class="fnt_sml" style="padding-top:10px;"><img src="images/FORM/OPT-1.png" width="39" height="8" /><span style="color:#FF0000"></span></td>
  </tr>
  <tr>
   <td  ><input type="text" name="Name" id="Name" class="input_left" value='<?php echo $LastName?>' />
<span style="clear:left;" class="input_left_error" ><?php echo $msgName?></span></td>
  </tr>
 <tr>
    <td class="fnt_sml"><img src="images/FORM/OPT-3.png" /></span></td>

  </tr>
  <tr>
    <td><input type="text" name="Email" id="Email" class="input_left" value='<?php echo $Email ?>' />

<span style="clear:left;" class="input_left_error" ><?php echo $msgEmail ?></span></td>

  </tr>
  <tr>
    <td class="fnt_sml"><img src="images/FORM/OPT-4.png" /></td>
  </tr>
  <tr>
    <td><input type="text" name="Phone" id="Phone" class="input_left" value='<?php echo $Phone ?>' />

<span style="clear:left;" class="input_left_error" ><?php echo $msgPhone ?></span></td>

  </tr>
  <tr>
   <td class="fnt_sml"><img src="images/FORM/OPT-5.png" width="57" height="10" /></td>

  </tr>
  <tr>
    <td class="fnt_sml"><input type="text" name="TelPhone" class="input_left" id="TelPhone" value='<?php echo $TelPhone?>' />
    <span style="clear:left;" class="input_left_error"><?php echo $msgTelPhone ?></span></td>
  </tr>
 <tr>
   <td class="fnt_sml"><img src="images/FORM/OPT-2.png" /></td>

  </tr>
  <tr>
    <td><textarea name="Message" id="Message" rows="5" cols="25" class="input_left" value='<?php echo $Message?>'></textarea>

<span style="clear:left;" class="input_left_error" ><?php echo $msgMessage ?></span></td>
   </tr>
  <tr>
    <td class="fnt_sml"><img src="images/FORM/OPT-6.png" width="89" height="8" /></td>

  </tr>
  <tr>
    <td align="center"><input type="text" name="keycode" id="keycode" size="20" class="input_left" style="width:170px;" value='<?php echo $keycode ?>' />

<span style="clear:left;" class="input_left_error" > <?php echo $msgkeycode ?> </span>

<img src="CaptchaSecurityImages.php" id="refcaptimg" align="middle" style="margin-top:5px;" alt="" />&nbsp;<a href="javascript:refreshCaptcha('images/')"><img  src="images/hip_reload.gif" width="22" height="22" border="0" align="middle" style="margin-top:1px;" alt="" /></a>
          <a href="javascript:refreshCaptcha('images/')"><span class="style1" style="color: #FE4819"></span></a>

      <div class="input_left_error"></div></td>
  </tr>
  <tr>
    <td align="center"><input type="submit" name="Submit" value="Submit" style="background-color:#2172B8; color:#ffffff; border:solid 1px #2172B8;" />
</td>
</tr>
</table>
</form>

PHP Code Follow us : Contact-us.php

<?php if(isset($_POST[Submit])){

if(empty($_POST[Name])){$msgName='Please Enter Your Name.'; $Name= false;}
 else{$Name=$_POST[Name];}

if(empty($_POST[Message])) {$msgMessage= 'Please Enter your message.'; $Message=false; }
       else{$Message=$_POST[Message];}

if(empty($_POST[Email])){$msgEmail='Please Enter Your Email-Id';$Email= false; }
 else{$Email=$_POST[Email];}
 if (!eregi("^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$", $_POST[Email])){ $msgEmail= 'Please Enter A Valid Email Address'; $Email = false; }
 else{$Email=$_POST[Email];}

if(empty($_POST[Phone])){$msgPhone='Please Enter Your Contact No. '; $Phone= false;}
 else{$Phone=$_POST[Phone];}
 if(!eregi("[0-9.-\+]", $_POST[Phone])) {$msgPhone='Please enter a valid contact no. '; $Phone=false;}
 else{ $Phone=$_POST[Phone];}

 $TelPhone=$_POST[TelPhone];

if($_POST[keycode]!=$_SESSION[keycode] OR $_SESSION[keycode]==''){$msgkeycode = 'Incorrect verification code';$keycode = false;}
 else{$keycode=$_POST[keycode];}
 if($Name  && $Message && $Email && $Phone && $Message && $keycode)
 {
  header("Location: $tpage");
exit;
}else{ index.php } ?>

CSV File Upload Import Database In php mysql

CSV File Upload Import Database In php mysql
http://www.developerinvention.in/2016/04/how-to-create-and-download-csv-file.html?m=1 More data csv format insert database import csv format data.
Create can file

CSV File Upload Import Database In php mysql

CSV File Upload Import Database In php mysql


<?php
include("includes/header.php");
function remostrtag($a)
{
    return mysql_escape_string(trim($a));
}
 $error_msg='';
function redvv($b)
{
    return str_replace(" ","",strtolower($b));
}
if (isset($_REQUEST['submit']) || isset($_REQUEST['submit_x'])) {
    
     $file_size = $_FILES['cfile']['size']; 
  // echo  "===>>>".$file_type = $_FILES['cfile']['type']; exit;
    
   
   $filecheck = basename($_FILES['cfile']['name']);
 $ext = substr($filecheck, strrpos($filecheck, '.') + 1);
   /*
 if (($file_size > 2097152)){      
        $message = 'File too large. File must be less than 2 megabytes.'; 
        echo '<script type="text/javascript">alert("'.$message.'");</script>'; 
    }
 */
 $repary=array();
  if(strtolower($ext)=='csv')
   {
$handle = fopen($_FILES['cfile']['tmp_name'], "r");
$hj=0;
while (($data = fgetcsv($handle, 4000, ",")) !== FALSE) {
//print_r($data).'<br/><br/>';
            $hj++;
            $sts=0;
              if($hj==1 && (redvv($data[0])!='sl.no' || redvv($data[1])!='name' || redvv($data[2])!='sex'  || redvv($data[3])!='yearofstudy' || redvv($data[4])!='class'   || redvv($data[5])!='presentposition'  || redvv($data[6])!='telephoneno' || redvv($data[7])!='emailid')){
                header("location:alumnicsvfile.php?fort");
   exit; 
            }
          
            
            if($hj>1){
                $qrychk=mysql_query("select * from tblmini where LOWER(`firstname`)='".strtolower(remostrtag($data[1]))."'");
               // if(mysql_num_rows($qrychk) =0)
                //{
//                   $grpid=getret_cln_grpid($data[3]); 
                   // if(strtolower($data[11])=='active')
                 //   {
                        $sts=1;
                 //   }
                    
                    $add=$data[5].','.$data[6];
$emapass = explode('@',$data[7]);
$passd = $emapass[0].'123';
// ECHO $passd.'<br/><br/>';
         $import="INSERT into tblmini(firstname,gender,batch,phone,email,password) values('$data[1]','$data[2]','$data[3]','$data[6]','$data[7]','$passd')";
//echo $import; 
mysql_query($import);
                //}else{
                //    $repary[]=$data[0];
               // }
}
        }
       //exit;
fclose($handle);
         if(!empty($repary))
        {
             $error_msg='S.no '.implode(",",$repary).' values are not inserted';
        }else{
   header("location:mnicsvfile.php?suc");
   exit;
        }
}else
{
    header("location:mnicsvfile.php?err");
   exit;
    $error_msg='Please upload Correct CSV file';
}
}
     ?>
 
<div id="content" class="app-content" role="main">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3" style="font-size: 22px;">
            Upload <i class="fa fa-angle-double-right"></i> Alumni CSV File Upload
        </h1>
    </div>
    <div class="wrapper-md">
        <!-- toaster directive -->
        <toaster-container
            toaster-options="{'position-class': 'toast-top-right', 'close-button':true}"></toaster-container>
        <!-- / toaster directive -->
        <div class="panel panel-default">
            <div class="panel-heading" style="height: 3.5em">
                <span style="color:#F00;float:left;font-style: none">* Marked fields are mandatory</span>
              
            </div>
            <div class="panel-body">
                <form  method="post" action="" class="form-validation" enctype="multipart/form-data">
                    <div class="form-group">
<?php
if( $error_msg!=''){
     echo '<div class="col-sm-12 fromdel" >'.$error_msg.'</div>';
}else{
if (isset($_REQUEST['suc'])) {
    echo '<div class="col-sm-12 fromsuc" style="float:left; height:30px;">Successfully Imported</div>';
}
if (isset($_REQUEST['up'])) {
    echo '<div class="col-sm-12 fromupd" >Successfully Updated</div>';
} if (isset($_REQUEST['del'])) {
    echo '<div class="col-sm-12 fromdel" >Successfully Deleted</div>';
}
if (isset($_REQUEST['err'])) {
    echo '<div class="col-sm-12 fromdel" style="color:red">Please upload Correct CSV file</div>';
}
if (isset($_REQUEST['fort'])) {
    echo '<div class="col-sm-12 fromdel" style="color:red">Please upload Correct field name in CSV file</div>';
}
}
?>
                    </div>
                  
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">Csv File<span style="color:#F00">*</span></label>
                        <div class="col-sm-10">
                            <div class="btn-group">
                                <input type="file" name="cfile" />
                            </div>
                        </div>
                    </div>
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                   
                    <footer class="panel-footer text-center bg-light lter">
 <button type="submit"
                                    class="btn m-b-xs btn-sm btn-success btn-addon"
                                    name="submit" value="submit" >
                                <i class="fa fa-save"></i>Upload
                            </button>
                    </footer>
                </form>
            </div>
        </div>
    </div>
</div>  
<?php
include("includes/footer.php");
?>