Friday, 1 July 2016

Tuesday, 28 June 2016

How to convert stdclass object to Array and Array To stdclass Object

//Object To Array

function object2Array($d)
{
if (is_object($d))
{
$d = get_object_vars($d);
}

if (is_array($d))
{
return array_map(__FUNCTION__, $d);
}
else
{
return $d;
}
}

//   After  This

  $attachments_id=$value -> attachments;
   $attachments_array = object2Array($attachments_id);
   foreach($attachments_array as $attachments_data)
   {
        echo "=====================Start Attachments  Data =================================<br/>";
echo "ID&nbsp; : ".$attachments_data['id']."<br/>";
echo "uploaded_name&nbsp; :".$attachments_data['uploaded_name']."<br/>";
echo "uploaded_extension&nbsp; : ".$attachments_data['uploaded_extension']."<br/>";
echo "mime_type&nbsp; : ".$attachments_data['mime_type']."<br/>";
echo "file_size&nbsp; :".$attachments_data['file_size']."<br/>";
echo "url&nbsp; : ".$attachments_data['url']."<br/>";
echo "=====================End Attachments Data =================================<br/>";
   }

// Array To Object

function array2Object($d)
{
if (is_array($d))
{
return (object) array_map(__FUNCTION__, $d);
}
else
{
return $d;
}
}

$object = array2Object($array);
print_r($object);
echo "\r\n";


Click  Here

Tuesday, 31 May 2016

PDF invoice for each order in magento

Step 1

Create the following three files in your Magento’s installation:
app/code/local/Inchoo/Invoice/Model/Order/Pdf/Items/Invoice/Default.php
app/code/local/Inchoo/Invoice/Model/Order/Pdf/Invoice.php
app/code/local/Inchoo/Invoice/etc/config.xml

Those will be used for our extension that will modify Magento’s core functionality.

Step 2

config.xml
=========

<?xml version="1.0"?> <config> <modules> <Inchoo_Invoice> <version>0.1.0</version> </Inchoo_Invoice> </modules> <global> <models> <sales> <rewrite> <order_pdf_invoice>Inchoo_Invoice_Model_Order_Pdf_Invoice</order_pdf_invoice> <order_pdf_items_invoice_default>Inchoo_Invoice_Model_Order_Pdf_Items_Invoice_Default</order_pdf_items_invoice_default> </rewrite> </sales> </models> </global> </config>


===========================================
Default.php

<?php /** * Inchoo PDF rewrite for custom attribute * Attribute "inchoo_warehouse_location" has to be set manually * Original: Sales Order Invoice Pdf default items renderer * * @category Inchoo * @package Inhoo_Invoice * @author Mladen Lotar - Inchoo <mladen.lotar@inchoo.net> */   class Inchoo_Invoice_Model_Order_Pdf_Items_Invoice_Default extends Mage_Sales_Model_Order_Pdf_Items_Invoice_Default { /** * Draw item line **/ public function draw() { $order = $this->getOrder(); $item = $this->getItem(); $pdf = $this->getPdf(); $page = $this->getPage(); $lines = array();   //Inchoo - Added custom attribute to PDF, first get it if exists $WarehouseLocation = $this->getWarehouseLocationValue($item);   // draw Product name $lines[0] = array(array( 'text' => Mage::helper('core/string')->str_split($item->getName(), 60, true, true), 'feed' => 35, ));   //Inchoo - Added custom attribute //draw Warehouse Location $lines[0][] = array( 'text' => Mage::helper('core/string')->str_split($WarehouseLocation, 25), 'feed' => 245 );   // draw SKU $lines[0][] = array( 'text' => Mage::helper('core/string')->str_split($this->getSku($item), 25), 'feed' => 325 );   // draw QTY $lines[0][] = array( 'text' => $item->getQty()*1, 'feed' => 435 );   // draw Price $lines[0][] = array( 'text' => $order->formatPriceTxt($item->getPrice()), 'feed' => 395, 'font' => 'bold', 'align' => 'right' );   // draw Tax $lines[0][] = array( 'text' => $order->formatPriceTxt($item->getTaxAmount()), 'feed' => 495, 'font' => 'bold', 'align' => 'right' );   // draw Subtotal $lines[0][] = array( 'text' => $order->formatPriceTxt($item->getRowTotal()), 'feed' => 565, 'font' => 'bold', 'align' => 'right' );   // custom options $options = $this->getItemOptions(); if ($options) { foreach ($options as $option) { // draw options label $lines[][] = array( 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 70, true, true), 'font' => 'italic', 'feed' => 35 );   if ($option['value']) { $_printValue = isset($option['print_value']) ? $option['print_value'] : strip_tags($option['value']); $values = explode(', ', $_printValue); foreach ($values as $value) { $lines[][] = array( 'text' => Mage::helper('core/string')->str_split($value, 50, true, true), 'feed' => 40 ); } } } }   $lineBlock = array( 'lines' => $lines, 'height' => 10 );   $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true)); $this->setPage($page);   }   /* * Return Value of custom attribute * */ private function getWarehouseLocationValue($item) { $prod = Mage::getModel('catalog/product')->load($item->getProductId());   if(!($return_location = $prod->getInchooWarehouseLocation())) return 'N/A'; else return $return_location; } }

===============================================
Invoice.php

<?php /** * Inchoo PDF rewrite for custom attribute * * Attribute "inchoo_warehouse_location" has to be set manually * Original: Sales Order Invoice PDF model * * @category Inchoo * @package Inhoo_Invoice * @author Mladen Lotar - Inchoo <mladen.lotar@inchoo.net> */ class Inchoo_Invoice_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice { public function getPdf($invoices = array()) { $this->_beforeGetPdf(); $this->_initRenderer('invoice');   $pdf = new Zend_Pdf(); $this->_setPdf($pdf); $style = new Zend_Pdf_Style(); $this->_setFontBold($style, 10);   foreach ($invoices as $invoice) { if ($invoice->getStoreId()) { Mage::app()->getLocale()->emulate($invoice->getStoreId()); } $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page;   $order = $invoice->getOrder();   /* Add image */ $this->insertLogo($page, $invoice->getStore());   /* Add address */ $this->insertAddress($page, $invoice->getStore());   /* Add head */ $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId()));   $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $this->_setFontRegular($page); $page->drawText(Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId(), 35, 780, 'UTF-8');   /* Add table */ $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92)); $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5)); $page->setLineWidth(0.5);   $page->drawRectangle(25, $this->y, 570, $this->y -15); $this->y -=10;   /* Add table head */ $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4)); $page->drawText(Mage::helper('sales')->__('Products'), 35, $this->y, 'UTF-8'); //Added for custom attribute "inchoo_warehouse_location" $page->drawText(Mage::helper('sales')->__('Warehouse Location'), 245, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('SKU'), 325, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');   $this->y -=15;   $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));   /* Add body */ foreach ($invoice->getAllItems() as $item){ if ($item->getOrderItem()->getParentItem()) { continue; }   if ($this->y < 15) { $page = $this->newPage(array('table_header' => true)); }   /* Draw item */ $page = $this->_drawItem($item, $page, $order); }   /* Add totals */ $page = $this->insertTotals($page, $invoice);   if ($invoice->getStoreId()) { Mage::app()->getLocale()->revert(); } } $this->_afterGetPdf();   return $pdf; }   public function newPage(array $settings = array()) { /* Add new table head */ $page = $this->_getPdf()->newPage(Zend_Pdf_Page::SIZE_A4); $this->_getPdf()->pages[] = $page; $this->y = 800;   if (!empty($settings['table_header'])) { $this->_setFontRegular($page); $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92)); $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5)); $page->setLineWidth(0.5); $page->drawRectangle(25, $this->y, 570, $this->y-15); $this->y -=10;   $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4)); $page->drawText(Mage::helper('sales')->__('Product'), 35, $this->y, 'UTF-8'); //Added for custom attribute "inchoo_warehouse_location" $page->drawText(Mage::helper('sales')->__('Warehouse Location'), 245, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('SKU'), 325, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');   $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $this->y -=20; } return $page; } }

==============

Step 3


Now, you’ve done it. Test it out by going to “Sales->Invoices->(View any of them)->Print”. You shoud be asked to download PDF, and when you do, it should contain “Warehouse Location” by each of order items.
All you have to do is test it out and / or change it according to your needs!
I hope this was of help to someone!

Wednesday, 2 March 2016

How to Registration and user chacked Api in PHP

<?php

// Include confi.php
include_once('../confi.php');
//$apikey = "123456789";
//if ($_GET['apikey'] == $apikey) {

if($_SERVER['REQUEST_METHOD'] == "POST"){
// Get data
$fname = isset($_POST['fname']) ? mysql_real_escape_string($_POST['fname']) : "";
$lname = isset($_POST['lname']) ? mysql_real_escape_string($_POST['lname']) : "";
$email= isset($_POST['email']) ? mysql_real_escape_string($_POST['email'])  : "";
$mobile_number = isset($_POST['mobile_number']) ? mysql_real_escape_string($_POST['mobile_number']) : "";
$house_number= isset($_POST['house_number']) ? mysql_real_escape_string($_POST['house_number']) : "";
$pass= isset($_POST['pass']) ? mysql_real_escape_string($_POST['pass']) : "";
$r_city= isset($_POST['r_city']) ? mysql_real_escape_string($_POST['r_city']) : "";
$r_socitey= isset($_POST['r_socitey']) ? mysql_real_escape_string($_POST['r_socitey']) : "";



// Insert data into data base
//$sql = "INSERT INTO `sub_category` (`subcat_id`,`sub_name`,`sub_description`,`category_id`) VALUES (NULL,'$subcat_name','$sub_description','$catgory_id');";
 $sql = "insert into register(r_id,fname,lname,email,mobile_number,house_number,pass,r_city,r_socitey) VALUES (NULL,'$fname','$lname','$email','$mobile_number','$house_number','$pass','$r_city',$r_socitey)";
$qur = mysql_query($sql);
$result =array();
if($qur){
$result[] = array("msg" => "Your Registration Has Completed Successfully","r_id" => mysql_insert_id(),"fname" => $fname,"lname" => $lname,"email" => $email,"mobile_number" => $mobile_number,"house_number" => $house_number,"r_city" => $r_city,"r_socitey" => $r_socitey);

$json = array("status" => 1, "info" => $result);
}else{
$json = array("status" => 0, "msg" => "Error Registration Form ");
}


}else{
$json = array("status" => 0, "msg" => "Request method not accepted");
}



@mysql_close($conn);

/* Output header */
header('Content-type: application/json');
echo json_encode($json);

Monday, 29 February 2016

HOw to Update Join Query in Mysql

Query
 ======
 $sql="Update sub_category as  sub,category as cat SET sub.sub_name='$itemname',sub.sub_description='$txtitemdesc',sub.stock_day='$txtstockday',cat.category_description='$txtcatdesc',cat.category_name='$txtcatname' where sub.category_id=cat.cat_id and sub.subcat_id='$idget'";

 Example
 ========
 Update sub_category as sub,category as cat SET sub.sub_name='poteto1',sub.sub_description='This is poteto1',sub.stock_day='71',cat.category_description='In everyday usage, a vegetable is any part of a plant that is consumed by humans as food as part of a savory meal.1',cat.category_name='Vegetables1' where sub.category_id=cat.cat_id and sub.subcat_id='5'

Thursday, 11 February 2016

How To bulk product import woocommerce Wordpress

Step-1  Installation This Plugin
        Name Import any XML or CSV File to WordPress
        Link

Step-2  Download  plugins
        Name WP All Import - WooCommerce Add-On
        Link

Friday, 29 January 2016

How to pagination and search,ascending or descending display data With javascript



This Code put Header Part 
=====================================
<link href='https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css' rel='stylesheet' type='text/css'>
<script src="//code.jquery.com/jquery-1.12.0.min.js" type="text/javascript"></script>
 <script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js" type="text/javascript"></script>
 <script>
$(document).ready(function() {
    $('#example').DataTable( {
        "order": [[ 3, "desc" ]]
    } );
} );
</script>
=====================================
This Code in your Body tag 
<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
        <tbody>
            <tr>
                <td>Tiger Nixon</td>
                <td>System Architect</td>
                <td>Edinburgh</td>
                <td>61</td>
                <td>2011/04/25</td>
                <td>$320,800</td>
            </tr>
</tbody>
    </table>
=========================
 then Run Click here

Friday, 22 January 2016

How to Database copy to All table with Database in mysql

Step 1
    Go to your Old Database  then
Step 2
    select   oprations tab
Step 3   Copy database to:
         select Switch to copied database
select Add AUTO_INCREMENT value
select CREATE DATABASE before copying
select  Structure and data


Click Here

 

Friday, 8 January 2016

PayPal gateway has rejected request. Payment has already been made for this InvoiceID (#10412: Duplicate invoice) in magento



Step 1 > Enter your business account and go to Profile
Step 2 > payment Recieving  Preferences
Step 3 >and set Block accidental payments to No.

 Click 

Thursday, 24 December 2015

webpage has a redirect loop in magento 2



step: 1 Go to Phpmyadmin
          search core_config_data
step: 2 Edit the rows entitled web/unsecure/base_url and  web/secure/base_url
        http://127.0.0.1/magento_sample/  and
https://127.0.0.1/magento_sample/
step: 3 Edit the row web/url/redirect_to_base to 0 instead of 1
step: 4 Clear contents of both var/cache and var/sessions folders.

cheack your Admin url Work.....

Details

Saturday, 19 December 2015

How to Insert Data in Android to Mysql API

<?php

// Include confi.php
include_once('../confi.php');
//$apikey = "123456789";
//if ($_GET['apikey'] == $apikey) {

if($_SERVER['REQUEST_METHOD'] == "POST"){
// Get data
$category_name = isset($_POST['cat_name']) ? mysql_real_escape_string($_POST['cat_name']) : "";
$category_description = isset($_POST['cat_description']) ? mysql_real_escape_string($_POST['cat_description']) : "";
// Insert data into data base
$sql = "INSERT INTO `category` (`cat_id`,`cat_name`,`cat_description`) VALUES (NULL,'$category_name','$category_description');";
$qur = mysql_query($sql);

$result =array();
if($qur){
$result[] = array("msg" => "Done adding category!","Category Name" => $category_name,"Category Description" => $category_description);
$json = array("status" => 1, "info" => $result);
}else{
$json = array("status" => 0, "msg" => "Error adding category!");
}
}else{
$json = array("status" => 0, "msg" => "Request method not accepted");
}

@mysql_close($conn);

/* Output header */
header('Content-type: application/json');
echo json_encode($json);
//}
//else {
// echo "Access Denied";
//}

Saturday, 12 December 2015

Adding New Products with Built in Magento Tools

step 1 Go Categories
step 2  Custom Design Tab
Step 3  Copy Below Text
         <reference name="content">
               <block type="catalog/product_new" name="product_new" template="catalog/product/list.phtml">
               <action method="setCategoryId"><category_id>10</category_id></action>
                <action method="setColumnCount"><column_count>6</column_count></action>
                <action method="setProductsCount"><count>0</count></action>
             <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                <block type="page/html_pager" name="product_list_toolbar_pager" />
                  <action method="setDefaultGridPerPage"><limit>12</limit></action>
                  <action method="addPagerLimit"><mode>grid</mode><limit>12</limit></action>
                 <action method="addPagerLimit"><mode>grid</mode><limit>24</limit></action>
                 <action method="addPagerLimit"><mode>grid</mode><limit>36</limit></action>
                <action method="addPagerLimit"><mode>grid</mode><limit>48</limit></action>
                <action method="addPagerLimit" translate="label"><mode>grid</mode><limit>all</limit><label>All</label></action>
              </block>
             <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>6</count></action>
               <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
              </block>
            </reference>

Step 4 Then Run

follow This link

Friday, 11 December 2015

There has been an error processing your request in magento

  • step 1     One by one, disable recently installed modules by changing <active>true</active>to <active>false</active> in app/etc/modules/<MODULE_NAME>.xml, where <MODULE_NAME> should be replaced with actual module name you installed recently.  follow This link Answer

Wednesday, 9 December 2015

After installation magento 2 then admin link not work

Before




After installing Magento 2 in Windows under Xampp, if your admin and front end link’s are not working, please follow the below steps to fix the same…
  1. Remove everything, except .htaccess file from pub/static folder
  2. Open up app/etc/di.xml find the path “Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink” and replace to “Magento\Framework\App\View\Asset\MaterializationStrategy\Copy”
Note: Remove entire files and folder under pub/static except .htaccess file.

After Link are Activate




how to solve PHP Extensions check in magento 2



step 1 Go to php.ini
step 2 find for ;extension=php_intl.dll
step 3 remove the comment ;

restart xampp 

Monday, 16 November 2015

Item (Mage_Catalog_Model_Product) with the same id already exist in magento

 This is my solution
 step 1  Edit : /www/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php
Line: 256

step 2 Replace: return parent::addItem($object);

With: try { return parent::addItem($object); } catch (Exception $ex) { } 

Tuesday, 3 November 2015

There has been an error processing your request admin panel in magento

step 1  main directory in tmp folder create
step 2  tmp folder Set directory permissions to 777 or 755
step 3 Open “lib/Zend/Cache/Backend/File.php“
step 4 locate the following code

protected $_options = array( ‘cache_dir’ => null

and replace with

protected $_options = array( ‘cache_dir’ => ‘tmp’

sqlstate hy000 1045 access denied for user localhost using password yes in magento

step 1   change local.xml.sample to local.xml
stpe 2   change the detabese user name and password

Thursday, 29 October 2015

How to mail function in magento

http://www.magentocommerce.com/magento-connect/disable-email-notifications.html

Monday, 5 October 2015

validation with login

<script type="text/javascript">
/*
function demo()
{
var fn = document.getElementById("fn");
var email = document.getElementById("email");
var contact = document.getElementById("contact");
var pass = document.getElementById("pass");
var repass = document.getElementById("repass");

if((fn.value=="") || (fn.value.search(/^[A-Za-z]+$/)))
{
alert('Enter Name');
fn.focus();
return false;
}

var RegExEmail = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}.$/i;

if((email.value=="") ||(!RegExEmail.test(email.value)))
{
alert('Enter email');
email.focus();
return false;
}

if((contact.value=="") || (contact.value.search(/^[0-9]+$/)) || (contact.value.length<10))
{
alert('Enter Contact');
contact.focus();
return false;
}

if((pass.value=="") || (repass.value==""))
{
alert('Enter password twise');
pass.focus();
return false;
}

if(pass.value!=repass.value)
{
alert('password not match');
pass.focus();
return false;
}
return true;
}
*/


</script>

<script type="text/javascript">

function demo(){

var fn = document.getElementById("fn");
var email = document.getElementById("email");
var contact = document.getElementById("contact");
var pass = document.getElementById("pass");
var repass = document.getElementById("repass");
var gender_m = document.getElementById("gender_m");
var gender_f = document.getElementById("gender_f");
var city = document.getElementById("city");

if(fn.value==''){
alert('Enter Name');
fn.focus();
return false;
}

if(fn.value.search(/^[A-Za-z]+$/)){
alert('Enter Valid Name');
fn.focus();
return false;
}

if(email.value.search(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}.$/i)){
alert('Enter Valid Email');
email.focus();
return false;
}

if(contact.value.search(/^[0-9]+$/)){
alert('Enter Valid Contact');
contact.focus();
return false;
}

if(contact.value.length<10){
alert('Must Be Enter 10 Digit');
contact.focus();
return false;
}

if(pass.value!=repass.value){
alert('Password Not Match');
repass.focus();
return false;
}

if(gender_m.checked==false && gender_f.checked==false){
alert('Choose Gender');
gender_m.focus();
return false;
}

if(city.value==''){
alert('Select City');
city.focus();
return false;
}



return true;

}


</script>



<form name="form" action="#" method="post">
Name :-
<input type="text" name="Fname" id="fn" /><br /><br />
Email :-
<input type="text" name="Email" id="email"/><br /><br />
Contact :-
<input type="text" name="contact" id="contact" maxlength="10"/><br /><br />
Password :-
<input type="text" name="password" id="pass" /><br /><br />
Re-Password :-
<input type="text" name="repass" id="repass" /><br /><br />
Gender :-
<input type="radio" name="gender" id="gender_m" value="Male" />Male
<input type="radio" name="gender" id="gender_f" value="Female" />Female<br /><br />
City :-
<select id="city">
<option value="">--Select--</option>
    <option value="AHM">Ahmedabad</option>
</select><br /><br />
<input type="submit" name="submit" value="submit" onclick="return demo();" />
</form>
*********************************product*******************
  <form action="insert_product1.php" method="post" enctype="multipart/form-data">
    <table>
     <tr>
       <td>Name:</td>
      <tD><input type="text" name="t1"></td>
      </tr>
       <tr>
       <td>Price:</td>
      <tD><input type="text" name="t2"></td>
      </tr>
     
    <tr>
      <td>Category:</td>
       <td>
         <select name="t3">
             <option value="Electronic">Electronic</option>
             <option value="Mobile">Mobile</option>        
         </select>
     </td>
    </tr>
 
 
    <tr>
       <td>Descrition:</td>
      <tD><input type="text" name="t4"></td>
      </tr>
    <tr>
      <td>Photo</td>
      <td><input type="file" name="t5"></td>
   </tr>
          <tr>
           <td>&nbsp;</td>
           <td><input type="submit" value="submit"></td>
      </tr>
  </table>
  </form>

  <?php

    $conn=new PDO("mysql:dbname=ssit","root","");
    $result=$conn->query("select *from product");
     
?>
   <table border="1">
      <tr>
         <td>&nbsp;</td>
          <td>&nbsp;</tD>
        <td>Product Id</td>
        <td>Product Name</td>
         <td>Price</td>
        <td>Category</td>
         <td>Description</tD>
        <td>Photo</td>
        </tr>
            <?php
                while($row=$result->fetch())
               {
                  ?>
                   <tr>
                      <td><a href='deleteproduct1.php?x=<?php echo $row["pid"]; ?>'>Delete</a></td>
                       <td><a href='editproduct1.php?x=<?php echo $row["pid"]; ?>'>Edit</a></td>

                       <td><?php echo $row["pid"]; ?></td>
                       <td><?php echo $row["name"]; ?></td>
                       <td><?php echo $row["price"]; ?></td>
                       <td><?php echo $row["category"]; ?></td>
                       <td><?php echo $row["description"]; ?></td>
                       <td><img src='<?php echo $row["photo"]; ?>' height="50" width="50" ></td>

                   </tr>
               <?php  
               }
             ?>
   </table>

****************************insert*******************
<?php
      $na=$_POST["t1"];
      $p=$_POST["t2"];
      $ct=$_POST["t3"];
      $des=$_POST["t4"];
      $fname=$_FILES["t5"]["name"];
      $path="photo/".$fname;

      move_uploaded_file($_FILES["t5"]["tmp_name"],$path);
      $conn=new PDO("mysql:dbname=ssit","root","");
      $conn->query("insert into product(name,price,category,description,photo) values('".$na."','".$p."','".$ct."','".$des."','".$path."')");
      header("Location:product.php");
 
  ?>
******************edit*************
  <?php
    $id=$_GET["x"];
    $conn=new PDO("mysql:dbname=ssit","root","");
    $rs=$conn->query("select *from product where pid='".$id."'");
    $rw=$rs->fetch();
   

  ?>

<form action="updateproduct1.php" method="post" enctype="multipart/form-data">
    <input type="hidden" name="pid" value='<?php echo $rw["pid"]; ?>'>
    <table>
     <tr>
       <td>Name:</td>
      <tD><input type="text" value='<?php echo $rw["name"] ?>' name="t1"></td>
      </tr>
       <tr>
       <td>Price:</td>
      <tD><input type="text" value='<?php echo $rw["price"] ?>' name="t2"></td>
      </tr>
     
    <tr>
      <td>Category:</td>
       <td>
         <select name="t3">
             <?php
                    if($rw["category"]=="Electronic")
                    {
                ?>
             <option value="Electronic" selected>Electronic</option>
             <option value="Mobile">Mobile</option>
                    <?php
                          }
                          else
                          {
                    ?>
             <option value="Electronic">Electronic</option>
             <option value="Mobile" selected>Mobile</option>
 
                       <?php
                       }
                      ?>  
         </select>
     </td>
    </tr>
 
 
    <tr>
       <td>Descrition:</td>
      <tD><input type="text"  value='<?php echo $rw["description"] ?>' name="t4"></td>
      </tr>
    <tr>
      <td>Photo</td>
      <td><input type="file" name="t5">
           <img src='<?php echo $rw["photo"] ?>' width="30" height="30">
</td>
             
   </tr>
          <tr>
           <td>&nbsp;</td>
           <td><input type="submit" value="Update"></td>
      </tr>
  </table>
  </form>

  <?php

    $result=$conn->query("select *from product");
     
?>
   <table border="1">
      <tr>
         <td>&nbsp;</td>
          <td>&nbsp;</tD>
        <td>Product Id</td>
        <td>Product Name</td>
         <td>Price</td>
        <td>Category</td>
         <td>Description</tD>
        <td>Photo</td>
        </tr>
            <?php
                while($row=$result->fetch())
               {
                  ?>
                   <tr>
                      <td><a href='deleteproduct1.php?x=<?php echo $row["pid"]; ?>'>Delete</a></td>
                       <td><a href='editproduct1.php?x=<?php echo $row["pid"]; ?>'>Edit</a></td>

                       <td><?php echo $row["pid"]; ?></td>
                       <td><?php echo $row["name"]; ?></td>
                       <td><?php echo $row["price"]; ?></td>
                       <td><?php echo $row["category"]; ?></td>
                       <td><?php echo $row["description"]; ?></td>
                       <td><img src='<?php echo $row["photo"]; ?>' height="50" width="50" ></td>

                   </tr>
               <?php  
               }
             ?>
   </table>

*******************delete*****************
<?php
       $id=$_GET["x"];
       
      $conn=new PDO("mysql:dbname=ssit","root","");
      $conn->query("delete from product where pid='".$id."'");
      header("Location:product1.php");
 
  ?>
***************************************update
<?php
      $na=$_POST["t1"];
      $p=$_POST["t2"];
      $ct=$_POST["t3"];
       $des=$_POST["t4"];
       $id=$_POST["pid"];

 
      $conn=new PDO("mysql:dbname=ssit","root","");

          $fname=$_FILES["t5"]["name"];
        if($fname=="")
           {
      $conn->query("update product set name='".$na."',price='".$p."',category='".$ct."',description='".$des."' where pid='".$id."'");
         }
        else
           {
              $path="photo/".$fname;
move_uploaded_file($_FILES["t5"]["tmp_name"],$path);
             $conn->query("update product set name='".$na."',price='".$p."',category='".$ct."',description='".$des."',photo='".$path."' where pid='".$id."'");
           }
     header("Location:product1.php");
 
  ?>
***************multi login******
<?php
   session_start();
   $l=$_POST["t1"];
   $p=$_POST["t2"];
 


 
  $conn=new PDO("mysql:dbname=project","root","");
 
  $result1=$conn->query("select *from admin where loginid='".$l."' and password='".$p."'");
  if($row1=$result1->fetch())
   {
     header("Location:admin_welcome.php");
   }
   else
   {
 
   $result=$conn->query("select *From business where loginid='".$l."' and password='".$p."'");
 
   if($row=$result->fetch())
     {
 $_SESSION["rid"]=$row["rid"];
       header("Location:welcome_business.php");
    }
else
{
    $result2=$conn->query("select *From user where loginid='".$l."' and password='".$p."'");
        if($row2=$result2->fetch())
{
    $_SESSION["rid"]=$row2["uid"];
       header("Location:welcome_viewer.php");
 }
 else
  {

header("Location:login.php");
 }
}

}
 
  ?>

Tuesday, 29 September 2015

Login with session in php

********login*************
  <form action="checklogin.php" method="post">
    <table>
 
    <tr>
       <td>Loginid:</td>
      <tD><input type="text" name="t1"></td>
      </tr>
     <tr>
       <td>Password:</td>
      <tD><input type="password" name="t2"></td>
      </tr>
          <tr>
           <td>&nbsp;</td>
           <td><input type="submit" value="submit">
      </tr>
  </table>
  </form>

*************chack.php*******

  <?php
     session_start();
     $l=$_REQUEST["t1"];
     $p=$_REQUEST["t2"];
     $conn=new PDO("mysql:dbname=ssit","root","");
     $result=$conn->query("select *From registration where loginid='".$l."' and password='".$p."'");
   if($row=$result->fetch())
    {
      echo "welcome user ".$row["name"];
      $_SESSION["u"]=$row["rid"];
     ?>
      <br>
      <a href="changeprofile.php">change profile</a>
  <?php
    }
    else
    {
        header("Location:login.php");
    }
  ?>
*****************sessio**********
<?php
session_start();
?>
<html>
<head>
<title>USe of Data</title>
</head>
<body>
<form action="session4.php" method="post">
<?php
if(isset($_SESSION['t1']))
{
echo "Welcome".$_SESSION['t1'];


?>
<input type="submit" name="submit" value="Logout" />
<?php
}
else
{
header("Location:session.php");
}
?>
</form>
</body>
</html>
***********************4**********
<?php
session_start();
session_destroy();
header("Location:session.php");
?>

Friday, 31 July 2015

How to COOKIE Example

<?php session_start(); ?>
<?php


  if(isset($_POST['txtname']) && isset($_POST['txtname']))
  {
    
              $username=$_POST['txtname'];
             $password=$_POST['txtpass'];
           
       
            if(isset($_POST['chlrember']) && $_POST['chlrember'] == 'on')
            {
   
                 setcookie('txtname',$username, time()+120);
                  setcookie('txtpass',$password, time()+120);
            }
            else { 
    //setcookie("txtname", $username, time()-120);
    //setcookie("txtpass", $password, time()-120);
          }
   
   
   
  } 
  else {
         
          $username = '';
          $password = '';
              if(isset($_COOKIE['txtname']))
                 { $username=$_COOKIE['txtname']; }
               
             if(isset($_COOKIE['txtpass']))
                { $password=$_COOKIE['txtpass'];  }
        }
   
 
 
 
   if(isset($_POST['btnlogin']))
   {
      if( $_POST['txtname']=='admin' &&  $_POST['txtpass']=='admin')
      {
         
         $_SESSION['my']=$_POST['txtname'];   
         header('location:list.php');   
       
      }
      else
      {
        echo "Wrong User name";
      }
     
   
   }

 
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
    <script type="text/javascript">
        function chkform(form)
        {
          if(form.txtname.value=="")
          {
         
           form.txtname.focus();
           document.getElementById("a1").innerHTML="Enter User Name";
           return false;
          }
          if(form.txtpass.value=="")
          {
                form.txtpass.focus();
                document.getElementById("a2").innerHTML="Enter Your Password";
                return false;
          }
          return true;
       
        }
    </script>
</head>


<body bgcolor="#999966">
<form name="lo1" method="post" onSubmit="return chkform(this)">
    <table>
         <tr>
            <tr>
                <th>User Name</th>
                <td><input type="text" name="txtname" placeholder="Enter User Name"  value="<?=$username;?>" ><span id="a1" style="color:red"></span></td>
               
            </tr>
            <tr>
                <th>Password</th>
                <td><input type="password" name="txtpass" placeholder="Enter Pssword" value="<?=$password;?>" ><span id="a2" style="color:red"></span></td>
            </tr>
            <tr>
                <td colspan="2"><input type="checkbox" name="chlrember" > Remember Me</td>
                
            </tr>
            <tr>
                <td><input type="submit" name="btnlogin" value="Login"></td>
            </tr>
        </tr>
    </table>   
</form>

</body>
</html>

 

How To login Page With Remember me with COOKIE

<?php session_start(); ?>
<?php


  if(isset($_POST['txtname']) && isset($_POST['txtname']))
  {
    
              $username=$_POST['txtname'];
             $password=$_POST['txtpass'];
           
       
            if(isset($_POST['chlrember']) && $_POST['chlrember'] == 'on')
            {
   
                 setcookie('txtname',$username, time()+120);
                  setcookie('txtpass',$password, time()+120);
            }
            else { 
    //setcookie("txtname", $username, time()-120);
    //setcookie("txtpass", $password, time()-120);
          }
   
   
   
  } 
  else {
         
          $username = '';
          $password = '';
              if(isset($_COOKIE['txtname']))
                 { $username=$_COOKIE['txtname']; }
               
             if(isset($_COOKIE['txtpass']))
                { $password=$_COOKIE['txtpass'];  }
        }
   
 
 
 
   if(isset($_POST['btnlogin']))
   {
      if( $_POST['txtname']=='admin' &&  $_POST['txtpass']=='admin')
      {
         
         $_SESSION['my']=$_POST['txtname'];   
         header('location:list.php');   
       
      }
      else
      {
        echo "Wrong User name";
      }
     
   
   }

 
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
    <script type="text/javascript">
        function chkform(form)
        {
          if(form.txtname.value=="")
          {
         
           form.txtname.focus();
           document.getElementById("a1").innerHTML="Enter User Name";
           return false;
          }
          if(form.txtpass.value=="")
          {
                form.txtpass.focus();
                document.getElementById("a2").innerHTML="Enter Your Password";
                return false;
          }
          return true;
       
        }
    </script>
</head>


<body bgcolor="#999966">
<form name="lo1" method="post" onSubmit="return chkform(this)">
    <table>
         <tr>
            <tr>
                <th>User Name</th>
                <td><input type="text" name="txtname" placeholder="Enter User Name"  value="<?=$username;?>" ><span id="a1" style="color:red"></span></td>
               
            </tr>
            <tr>
                <th>Password</th>
                <td><input type="password" name="txtpass" placeholder="Enter Pssword" value="<?=$password;?>" ><span id="a2" style="color:red"></span></td>
            </tr>
            <tr>
                <td colspan="2"><input type="checkbox" name="chlrember" > Remember Me</td>
                
            </tr>
            <tr>
                <td><input type="submit" name="btnlogin" value="Login"></td>
            </tr>
        </tr>
    </table>   
</form>

</body>
</html>

Thursday, 23 July 2015

How date regular expression in php validation

if(!preg_match('/^(19|20)\d\d[\-\/.](0[1-9]|1[012])[\-\/.](0[1-9]|[12][0-9]|3[01])$/',$txtstrtdate))
       {
           echo $error="In valid Date";
          $code="2";
       }

Wednesday, 22 July 2015

How To live Data Search with Ajax used LIKE Query

===================
list.php
===================

<script>
function showUser(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else {
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","getuser.php?q="+str,true);
        xmlhttp.send();
    }
}
</script>

</head>

<body>
<form name="f11" method="post">
<div>
<span style="color:#FFF">Enter * All Data Show</span>&nbsp;&nbsp;&nbsp;<input type="text"  onchange="showUser(this.value)"/></div>
<div id="txtHint"><b>Person info will be listed here...</b></div>
</form>
</body>
</html>
================
getuser.php
==============
<?php
include('connection.php');
$q =$_GET['q'];


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

if($q=='*')
{
 $sql="select * from employee ";
}
else
{
 $sql="SELECT * FROM employee WHERE emp_name OR emaill OR emp_username LIKE '%$q%'
AND emp_name OR emaill OR emp_username LIKE '%$q%'";
}

$result = mysqli_query($dd,$sql);
 $n=mysqli_num_rows($result);
  if($n > 0)
  {
echo "<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>

</tr>";
while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['emp_name'] . "</td>";
    echo "<td>" . $row['emaill'] . "</td>";
    echo "<td>" . $row['emp_username'] . "</td>";
  
    echo "</tr>";
}
echo "</table>";
  } else { echo "Data Not Found"; }
?>
</body>
</html>