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);
}
?>

Wednesday, November 21, 2018

How can edit the data in MySql using core php ?

form.php

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

//edit
if (isset($_REQUEST['edit_id']))
{
$eid=$_REQUEST['edit_id'];
$select="select * from tbl_user where id='$eid' ";
$ex=mysql_query($select);
$rec=mysql_fetch_array($ex);
}
?>
<html>
<head>
<title>insert the data</title>
</head>
<body>
<form method="post">
    <table border="1" align="center">
     <tr>
         <td>name</td>
            <td><input type="text" name="name" value="<?php echo $res['name']; ?>"></td>
        </tr>
        <tr>
         <td>password</td>
            <td><input type="text" name="pass" value="<?php echo $res['password']; ?>"></td>
        </tr>
        <tr>
         <td>gender</td>
< td>
<?php 
    $gen=$rec['gender']; // gender is the database table coulmn name
     if($gen=='male')
      {

?>
            <input type="radio" name="gender" value="male" checked='checked'>male
             <input type="radio" name="gender" value="female">female

<?php 
}  
else  if($gen=='female')
{ ?>
 <input type="radio" name="gender" value="male">male
 <input type="radio" name="gender" value="female" checked='checked'>male
          
<?php 
}
else 
{

?>
<input type="radio" name="gender" value="male">male
   <input type="radio" name="gender" value="female">female

<?php 
}?>
< /td>
        </tr>
        <tr>
         <td>hobby</td>
            <td>
<?php 
    $ex=$rec['hobby'];
    $h=explode("," , $ex);

if (isset($_REQUEST['edit_id']))
{
        if($h[0]=='cricket')
        { ?>
             <input type="checkbox" name="chk[]" value="cricket" checked='checked'>cricket
            <?php
              }
               else
               { ?>
           
            <input type="checkbox" name="chk[]" value="cricket">cricket
<?php 
}  
 if($h[0]=='hockey' || $h[1]=='hockey' )
{ ?>
  <input type="checkbox" name="chk[]" value="hockey" checked='checked'>hockey
            <?php }
               else
               { ?>
               <input type="checkbox" name="chk[]" value="hockey">hockey

<?php }}
else
{
?>
 <input type="checkbox" name="chk[]" value="cricket">cricket
<input type="checkbox" name="chk[]" value="hockey">hockey
<?php }
?>

< /td>
        </tr>
        <tr>
         <td colspan="2"><input type="submit" name="submit" value="submit"></td>
        </tr>
    </table>
    </form>
</body>
</html>


View.php---edit link

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

$s="select * from user";//select all records from user table
$ex=mysql_query($s);


?>
<html>
<head>
<style type="text/css">
table th{ background:#F93; color:white;}
table td{ background:#FC9;}
</style>
</head>
<body>
<form method="post">
<table  align="center">
<tr>
<th>id</th>
    <th>name</th>
    <th>pass</th>
    <th>gender</th>
    <th>hobby</th>\
< th>action</th>
    
</tr>
<?php
while ($ft=mysql_fetch_array($ex))   / /fetch the records using  mysql_fetch_array with  while loop
{
?>
<tr>
<td><?php echo $ft['id']; ?></td>
    <td><?php echo $ft['name']; ?></td>
    <td><?php echo $ft['pass']; ?></td>
    <td><?php echo $ft['gender']; ?></td>
    <td><?php echo $ft['hobby']; ?></td>
    <td><a href="form.php ? edit_id=<?php echo $ft['id']; ?>">edit</a></td>
</tr>
<?php
}
?>

</table>
</form>
</body>
</html>

How can edit the data in MySql using core php ?

form.php

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

//edit
if (isset($_REQUEST['edit_id']))
{
$eid=$_REQUEST['edit_id'];
$select="select * from tbl_user where id='$eid' ";
$ex=mysql_query($select);
$rec=mysql_fetch_array($ex);
}
?>
<html>
<head>
<title>insert the data</title>
</head>
<body>
<form method="post">
    <table border="1" align="center">
     <tr>
         <td>name</td>
            <td><input type="text" name="name" value="<?php echo $res['name']; ?>"></td>
        </tr>
        <tr>
         <td>password</td>
            <td><input type="text" name="pass" value="<?php echo $res['password']; ?>"></td>
        </tr>
        <tr>
         <td>gender</td>
< td>
<?php 
    $gen=$rec['gender']; // gender is the database table coulmn name
     if($gen=='male')
      {

?>
            <input type="radio" name="gender" value="male" checked='checked'>male
             <input type="radio" name="gender" value="female">female

<?php 
}  
else  if($gen=='female')
{ ?>
 <input type="radio" name="gender" value="male">male
 <input type="radio" name="gender" value="female" checked='checked'>male
          
<?php 
}
else 
{

?>
<input type="radio" name="gender" value="male">male
   <input type="radio" name="gender" value="female">female

<?php 
}?>
< /td>
        </tr>
        <tr>
         <td>hobby</td>
            <td>
<?php 
    $ex=$rec['hobby'];
    $h=explode("," , $ex);

if (isset($_REQUEST['edit_id']))
{
        if($h[0]=='cricket')
        { ?>
             <input type="checkbox" name="chk[]" value="cricket" checked='checked'>cricket
            <?php
              }
               else
               { ?>
           
            <input type="checkbox" name="chk[]" value="cricket">cricket
<?php 
}  
 if($h[0]=='hockey' || $h[1]=='hockey' )
{ ?>
  <input type="checkbox" name="chk[]" value="hockey" checked='checked'>hockey
            <?php }
               else
               { ?>
               <input type="checkbox" name="chk[]" value="hockey">hockey

<?php }}
else
{
?>
 <input type="checkbox" name="chk[]" value="cricket">cricket
<input type="checkbox" name="chk[]" value="hockey">hockey
<?php }
?>

< /td>
        </tr>
        <tr>
         <td colspan="2"><input type="submit" name="submit" value="submit"></td>
        </tr>
    </table>
    </form>
</body>
</html>

View.php---edit link

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

$s="select * from user";//select all records from user table
$ex=mysql_query($s);


?>
<html>
<head>
<style type="text/css">
table th{ background:#F93; color:white;}
table td{ background:#FC9;}
</style>
</head>
<body>
<form method="post">
<table  align="center">
<tr>
<th>id</th>
    <th>name</th>
    <th>pass</th>
    <th>gender</th>
    <th>hobby</th>\
< th>action</th>
    
</tr>
<?php
while ($ft=mysql_fetch_array($ex))   / /fetch the records using  mysql_fetch_array with  while loop
{
?>
<tr>
<td><?php echo $ft['id']; ?></td>
    <td><?php echo $ft['name']; ?></td>
    <td><?php echo $ft['pass']; ?></td>
    <td><?php echo $ft['gender']; ?></td>
    <td><?php echo $ft['hobby']; ?></td>
    <td><a href="form.php ? edit_id=<?php echo $ft['id']; ?>">edit</a></td>
</tr>
<?php
}
?>

</table>
</form>
</body>
</html>

Delete data using core php ?


<?php
 if(isset($_REQUEST['del_id']))
 {
    $del=$_REQUEST['del_id'];
     $de="delete from user where uid='$del'";
    $ex=mysql_query($del);     header("location:view.php");
 }


?>
< html>
< body>
<form method="post" name="form1" >
< table width="200" align="center" class="frm_tbl">
  <tr>
    <td>Uid</td>
    <td>Name</td>
    <td>Password</td>
    <td>Gender</td>
    <td>Hobby</td>
  </tr>
<?php
while($r = mysql_fetch_array($ex))
{
?>
  <tr>
     <td><?php echo $r['uid']; ?></td>
    <td><?php echo $r['name']; ?></td>
    <td><?php echo $r['password']; ?></td>
    <td><?php echo $r['Gender']; ?></td>
    <td><?php echo $r['Hobby']; ?></td>
  <td><a href="view.php?del_id=<?php echo $r['uid']; ?>">delete</td>
  </tr>
<?php
}
?>
< /table>
</form>



How can fetch the records in MySQL using php?

Create  a  form.php  for the inserting data & view.php for the fetching data in the  Data base

  • Fetching Records  in the database using Mysql_fetch_array ( ) Function.
  • Select Command use for the fetching data in database.
       make a form.php for inserting data & below view.php for fetch the records

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

//insert data in database using submit button request
if (isset($_REQUEST['submit']))
{
$n=$_REQUEST['name'];
$p=$_REQUEST['pass'];
$g=$_REQUEST['gender'];
$h=$_REQUEST['chk'];
if ($h)
{
$ch=implode(",",$h);//implode is a string function that are implode a multipal array value like chk[];
}
$ins="insert into user(name,pass,gender,hobby) values('$n','$p','$g','$ch')";
$ex=mysql_query($ins);
header ("location:view.php");//redirect the page on view.php
}
?>
<html>
<head>
<title>insert the data</title>
</head>
<body>
<form method="post">
    <table border="1" align="center">
     <tr>
         <td>name</td>
            <td><input type="text" name="name"></td>
        </tr>
        <tr>
         <td>password</td>
            <td><input type="text" name="pass"></td>
        </tr>
        <tr>
         <td>male</td>
            <td><input type="radio" name="gender" value="male">male<input type="radio" name="gender" value="female">female</td>
        </tr>
        <tr>
         <td>hobby</td>
            <td><input type="checkbox" name="chk[]" value="cricket">cricket<input type="checkbox" name="chk[]" value="hockey">hockey</td>
        </tr>
        <tr>
         <td colspan="2"><input type="submit" name="submit" value="submit"></td>
        </tr>
    </table>
    </form>
</body>
</html>

View.php for fetching data

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

$s="select * from user";//select all records from user table
$ex=mysql_query($s);


?>
<html>
<head>
<style type="text/css">
table th{ background:#F93; color:white;}
table td{ background:#FC9;}
</style>
</head>
<body>
<form method="post">
<table  align="center">
<tr>
<th>id</th>
    <th>name</th>
    <th>pass</th>
    <th>gender</th>
    <th>hobby</th>
    
</tr>
<?php
while ($ft=mysql_fetch_array($ex))   / /fetch the records using  mysql_fetch_array with  while loop
{
?>
<tr>
<td><?php echo $ft['id']; ?></td>
    <td><?php echo $ft['name']; ?></td>
    <td><?php echo $ft['pass']; ?></td>
    <td><?php echo $ft['gender']; ?></td>
    <td><?php echo $ft['hobby']; ?></td>
</tr>
<?php
}
?>

</table>
</form>
</body>
</html>

Output on a Browser:- 

How can insert the data in mysql using php?

step 1:- Firstly create a database name & secondly create a table in MySQL.

step 2:-After that create a table structure eg. Column Name1 , Coulmn Name2 , Coulmn NameN...

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

//insert data in database using submit button request
if (isset($_REQUEST['submit']))
{
$n=$_REQUEST['name'];
$p=$_REQUEST['pass'];
$g=$_REQUEST['gender'];
$h=$_REQUEST['chk'];
if ($h)
{
$ch=implode(",",$h);//implode is a string function that are implode a multipal array value like chk[];
}
$ins="insert into user(name,pass,gender,hobby) values('$n','$p','$g','$ch')";
$ex=mysql_query($ins);
}
?>
<html>
<head>
<title>insert the data</title>
</head>
<body>
<form method="post">
    <table border="1" align="center">
    <tr>
        <td>name</td>
            <td><input type="text" name="name"></td>
        </tr>
        <tr>
        <td>password</td>
            <td><input type="text" name="pass"></td>
        </tr>
        <tr>
        <td>male</td>
            <td><input type="radio" name="gender" value="male">male<input type="radio" name="gender" value="female">female</td>
        </tr>
        <tr>
        <td>hobby</td>
            <td><input type="checkbox" name="chk[]" value="cricket">cricket<input type="checkbox" name="chk[]" value="hockey">hockey</td>
        </tr>
        <tr>
        <td colspan="2"><input type="submit" name="submit" value="submit"></td>
        </tr>
    </table>
    </form>
</body>
</html>

Monday, November 12, 2018

PHP Error Types - And their Differences


Notices :

It will be shown in below condition like if we will try to access a variable which is not defined yet.
it will not stop script execution.

Warning :

It will be shown while using include(), it will not able to find file for include.
It will not stop script execution.

Fatal Error :

It will be shown while using require(), it will not able to find file at specified location.
it will stop script execution.

Parse Error :

It's’s syntax error or missing code error.
it will stop script execution.

Saturday, November 3, 2018

MySql Quaries


You can create and populate the example table with these statements:

CREATE TABLE shop ( article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL, dealer CHAR(20) DEFAULT '' NOT NULL, price DOUBLE(16,2) DEFAULT '0.00' NOT NULL, PRIMARY KEY(article, dealer)); INSERT INTO shop VALUES (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45), (3,'C',1.69),(3,'D',1.25),(4,'D',19.95);

After issuing the statements, the table should have the following contents:

SELECT * FROM shop; +---------+--------+-------+ | article | dealer | price | +---------+--------+-------+ | 0001 | A | 3.45 | | 0001 | B | 3.99 | | 0002 | A | 10.99 | | 0003 | B | 1.45 | | 0003 | C | 1.69 | | 0003 | D | 1.25 | | 0004 | D | 19.95 | +---------+--------+-------+

The Maximum Value of a Column:

SELECT MAX(article) AS article FROM shop; +---------+ | article | +---------+ | 4 | +---------+

Maximum of Column per Group:

Task: Find the highest price per article.

SELECT article, MAX(price) AS price FROM shop GROUP BY article; +---------+-------+ | article | price | +---------+-------+ | 0001 | 3.99 | | 0002 | 10.99 | | 0003 | 1.69 | | 0004 | 19.95 |
+---------+-------+

The Rows Holding the Group-wise Maximum of a Certain Column

Task: For each article, find the dealer or dealers with the most expensive price.
This problem can be solved with a subquery like this one:
SELECT article, dealer, price FROM shop s1 WHERE price=(SELECT MAX(s2.price) FROM shop s2 WHERE s1.article = s2.article); +---------+--------+-------+ | article | dealer | price | +---------+--------+-------+ | 0001 | B | 3.99 | | 0002 | A | 10.99 | | 0003 | C | 1.69 | | 0004 | D | 19.95 | +---------+--------+-------+