Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Tuesday, November 27, 2018

What is session in php? how can use the php session?

What is Session:- 
A php Session variable  is stored the single user information and are available all the page in the application.

A PHP session solves this problem by allowing you to store single user informations on the server at a time.session information is the temporary store on the server,you are left the site then will be deleted.

Session work on a unique ID because they are stored single unique value on the server. 

Starting a php session-
                                                   <?php
                                                                start_session(); // session is start
                                                       ?>

A simple Example describes below for using php session on a  page-
session.php

<?php
  session_start();
//session initialization 
  $_SESSION['view'] = 'rajendra'; // storing session (value rajendra) * view is session name this is optional if you want then change the name
  
?>
<?php
    echo "welcome " . $_SESSION['view'] . "<br/>"; 
// print the session value welcome  rajendra
?>


<?php
    if(isset($_SESSION['view']))
    {
        echo "Session is set..."; // session have a value then session is set 
    }
    else
    {
        echo "Session not set...";
    }
?>

<?php
    unset($_SESSION['view']); // unset the session value because session is logout
    session_destroy(); // delete all information of the session called session_destroy
    echo "session destroy...";
?>

Thursday, November 22, 2018

How to delete data from database using MVC?


Delete data from database using MVC

You can easily delete the records from database. In this below example we have used three php files

1. View.php

<?php
include("controller.php");
//delete the data
 if(isset($_REQUEST['del_id']))
 {
   $del=$_REQUEST['del_id'];

   $obj->delete($del);
   header("location:view.php");
}
?>
<html >
<head>
<title>Delete the data</title>
</head>
<body>
<form method="post" >
 <table align="center" border="1">
  <tr>
   <th>Uid</th>
   <th>Uname</th>
   <th>Password</th>
   <th colspan="2">Action</th>
  </tr>
  <?php
  while($r = mysql_fetch_array($s))
  {
  ?>
  <tr>
   <td><?php echo $r['uid']; ?></td>
   <td><?php echo $r['uname']; ?></td>
   <td><?php echo $r['pass']; ?></td>
   <td><a href="view.php?del_id=<?php echo $r['uid']; ?>">delete</td>
  </tr>
  <?php
  }
  ?>
 </table>
</form>
</body>
</html>
 

2. Model.php


<?php

public function delete($del){
  $del="delete from user where uid='$del'";
  $ex=mysql_query($del);
 }
?>



3. Controller.php



<?php
 include("model.php");
  public function delete($del){
  $obj=new model();
  $obj->delete($del);
 }
?>

How to update multiple table in MySQL?

Update multiple table with join in MYSQL


<?php
     $sql = "UPDATE table1
                 JOIN table2 VCR ON  (table1.contact_id = table2.contact_id)
                SET table1.email_status = 1,
                table2.review_status = 1
                WHERE table2.contact_id = 1005";
  ?>



Update single fields with join in MYSQL

<?php
   
$sql = "UPDATE table1 INNER JOIN table2 ON  table1.contactid = table2.contactid SET               table1.statue =1 WHERE  table2.crm_customer_id = 1004";

?>

Image upload by ajax in php

AJAX Image upload in php

It's very simple process to image upload by AJAX . It's working fine. You can easily upload the image by AJAX. Follow the below step. Code download  Click Here
1. Create a simple .php or .html file. We have created index.php file look below




<html>
<head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<div><b>Upload Profile Image By AJAX</b></div><br>
 <div class="calendra-popup-box custom-pp-image">
  <label>Profile Image</label>
  <input id="avatar" type="file" name="pimage" >
  <input type="hidden" id="base" value=""><br>
         <button id="submitImage">Save</button>
 </div>
</div>
</body>
</html>

<script type="text/javascript">
jQuery('#submitImage').click(function() {
  if ($("#avatar").prop("files")[0] ) {
            var reader = new FileReader();
             reader.onload = function (e) {
      $('#avatar').attr('src', e.target.result);
      $('#base').val(e.target.result);
      //var abc = $('#base1').attr('src', e.target.result);
  var imgdata = $('#base').val();
  var dataUrl = "ajaxResponse.php";
  $.ajax({
      type: "POST",
      url: dataUrl,
      data: {
          'imgres': imgdata,
      },
      success: function(result){
         alert('image upload sucessfully in folder');
       $('#avatar').val('');
         }
  });
     };
   reader.readAsDataURL($("#avatar").prop("files")[0]);
   }else{
    alert('Please Upload Image');
   }
})
</script>




2. Second file is ajaxResponse.php. There are managing image request data. look below.

<?php
$imgresEncode = $_REQUEST['imgres'];
if($imgresEncode !=''){
    $number = rand().'_'.date('Y-m-d');
    $split = explode(',', $imgresEncode,2);
    $extArr = explode(';', $split[0]);
    $extnsnArr = explode('/', $extArr[0]);
    $extns = end($extnsnArr);
    $img = str_replace(' ', '+', $split[1]);
    $data = base64_decode($img);
    $imageName  = "image_$number.".$extns;
    $actual_link = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
    $filepath = dirname(__FILE__)."/storage/profileimage/".$imageName;
    $success = file_put_contents($filepath, $data);
}
?>