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

Monday 28 September 2015

include , require and require_once , include_once in php

 include , require and require_once , include_once in php 


include, require and require_once,include_once are used to include a file into the PHP code

for example of include and require

<h1>Welcome to My blog!</h1>
<?php include 'header.php';
?>

it can added file in php code.

in require example

<h1>Welcome to My blog!</h1>
<?php require 'header.php';
?>

difference between  include and require

 when a file is included with the include statement and PHP cannot find it, the script will continue to execute

and

the echo statement will not be executed because the script execution dies after the require statement returned a fatal error

include_once 

It can be used include a PHP file another one, it can used to add files once. If it is found that the file has already been included, calling script is going to ignore further inclusions.

Syntax



include_once('name of the called file with path');

example 

<?php include_once('xyz.php'); 

?>

same as require_once used.

<?php require_once('example.php')  ?>

include_once and require_once same different with include and require.




Difference between Echo And Print In Php

Hello,

Here I can Give both of use echo and print in php. I give example and use.

Echo and Print are almost same. they are both output on screen. they are used with and without
parentheses.

Difference Echo And Print



  1. print return value and echo not return value.
  2. echo faster than print.
  3.  echo without parentheses can take multiple parameters, which get concatenated but print give error.

How Can Use.



$data = "hello".
$data1 ="jaydip";

echo "<h2>My echo information</h2>";
echo "namste !<br>";

echo $data."".$data1;


echo without parentheses can take multiple parameters 
echo "jj","123",1,3;

same like in Print:

$data = "hello".
$data1 ="jaydip";

print "<h2>My echo information</h2>";
print "namste !<br>";

print $data."".$data1;

you can use as print in 
$test=1;
($test==2) ? print "true" : print "false";


Friday 28 August 2015

Use Ternary Operator in Php

Hello

I am Here Create Some Example How to use Ternary operator in php.

Ternary Operator use as simple if and else condition

$bool_val = 5;

echo ($bool_val <= 5) ? 'true' : 'false';.

it result is true.

if $bool_val = 6. then out put will be different. it false.

before ? it's like if condition  and : else condition.

For Check this

<?php
$age = 18;
    $agestr = ($age < 18) ? 'child' : 'adult';

it same like this

<?php
      if ($age < 16) {
        $agestr = 'child';
    } else {
        $agestr = 'adult';
    }
 

?>

here

another example


        $valid = false;
    $lang = 'french';
    $x = $valid ? ($lang === 'french' ? 'oui' : 'yes') : ($lang === 'french' ? 'non' : 'no');
 
    echo $x;

like this

if($valid){
   
    if($lang === 'french')
    {
        $x='oui';
    }else{
        $x = 'yes';
    }
} else{
   
      if($lang === 'french')
    {
        $x='non';
    }else{
        $x = 'no';
    }
   
}
echo $x;




Tuesday 9 June 2015

Implode And Explode Function In Php

Hello All,

Here I Want give example of how to use implode and explode in php.

Use of Implode 


=> The implode() function returns a string from the elements of an array. separator parameter of implode() is optional.

I give example for it.


$array = array("hello","all","be","happy","always");

$result =  implode($array);

echo $result;

it result will be => helloallbehappyalways.

if you can separate array using space then you can write this way

 $result =  implode(" ",$array);

this result will me => hello all be happy always

you can any of parameter to separate array;

like i give emaple for it


echo $result =  implode("$",$array)."<br/>";
echo $result =  implode("+",$array)."<br/>";
echo $result =  implode("-",$array)."<br/>";
echo  $result =  implode("*",$array)."<br/>";

this result will me =>

hello$all$be$happy$always
hello+all+be+happy+always
hello-all-be-happy-always
hello*all*be*happy*always

I think yon can understand what implode work it can make string of array using separate
by it parameter.you can use different parameter that can separate it. 

Use of Explode

=> this function use of breaks a string into an array.separator parameter cannot be empty string.

i will give example for it.

$string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry";
$result = explode(" ",$string);
print_r($result);

this result will be=>
Array ( [0] => Lorem [1] => Ipsum [2] => is [3] => simply [4] => dummy [5] => text [6] => of [7] => the [8] => printing [9] => and [10] => typesetting [11] => industry )

if you want to separate to this different word.

if you to get separate word then check below code

echo "<br/>";
 $count = count($result);
 
 for($i=1;$i<=$count;$i++){
    
    $line =  each($result);
    print_r($line);
    echo "<br/>";
    echo $line['value']."<br/>";
 }

this out put will be
=>
Lorem
Array ( [1] => Ipsum [value] => Ipsum [0] => 1 [key] => 1 )
Ipsum
Array ( [1] => is [value] => is [0] => 2 [key] => 2 )
is
Array ( [1] => simply [value] => simply [0] => 3 [key] => 3 )
simply
Array ( [1] => dummy [value] => dummy [0] => 4 [key] => 4 )
dummy
Array ( [1] => text [value] => text [0] => 5 [key] => 5 )
text
Array ( [1] => of [value] => of [0] => 6 [key] => 6 )
of
Array ( [1] => the [value] => the [0] => 7 [key] => 7 )
the
Array ( [1] => printing [value] => printing [0] => 8 [key] => 8 )
printing
Array ( [1] => and [value] => and [0] => 9 [key] => 9 )
and
Array ( [1] => typesetting [value] => typesetting [0] => 10 [key] => 10 )
typesetting
Array ( [1] => industry [value] => industry [0] => 11 [key] => 11 )
industry

if you want to get only word echo $line['value]; use it and print_r($line); comment it.

you can also limit parameter to return a number of array elements

check this example

$string = "Lorem,Ipsum,is,simply,dummy,text,of,the,printing,and,typesetting,industry";

if you want to only 1 key then code this

print_r(explode(',',$string,0));

this result will =>
Array ( [0] => Lorem,Ipsum,is,simply,dummy,text,of,the,printing,and,typesetting,industry )

if you want 2 key then

print_r(explode(',',$string,2));

this result will=>
Array ( [0] => Lorem [1] => Ipsum,is,simply,dummy,text,of,the,printing,and,typesetting,industry )

if you want all key then you can use this code

print_r(explode(',',$string,-1));


this result will be =>

Array ( [0] => Lorem [1] => Ipsum [2] => is [3] => simply [4] => dummy [5] => text [6] => of [7] => the [8] => printing [9] => and [10] => typesetting )

this use of explode and implode. explode use for string to array and implode use for array to string.

 



 

Email Already Exit Using Jquery And Php

Hello All,

I am Simple Learn How to check email already exit. I am create code and check if

email already exit then you cannot submit  and also also validation of email.

I am give the code for that you can check it and use it.

you have to create to file

1)email.php
2)check.php

in your email.php wriite this code

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 
   $("#myform").submit(function(){
 
       if(!emailok)
       {
        alert('check your email');
        return false;
       }
   
    });
$('#email').blur(function(){
   alert($('#email').val());
    $.ajax({
        type:"post",
        data:"email="+$('#email').val(),
        url:"check.php",
        beforeSend:function(){
            $("#email_info").html("checking email...");
        },
        success:function(data){
         
            if(data == "invalid"){
                $("#email_info").html("check your Email");
           
       
            emailok = false;
            }else if(data !="0"){
                  $("#email_info").html("email already exit");
             
            }else{
            emailok = true;
            $("#email_info").html("email ok");
            }
         
         
        }
     
     
     
    });
 
    });
});
</script>
<form id="myform" method="post">
<input type="text" id="email" name="email"/>
<input type="submit" />
</form>
<div id="email_info"></div>


second file is check.php

add this code

<?php
 $dbhost = 'localhost';
   $dbuser = 'root';
   $dbpass = '';
   $conn = mysql_connect($dbhost, $dbuser, $dbpass);
   if(! $conn )
   {
     die('Could not connect: ' . mysql_error());
   }

 
   mysql_select_db('blog',$conn);
 
   $email = $_POST['email'];
 
   if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
 
   $sql =  mysql_query('select email from email where email="'.$email.'"' );
 
   $result = mysql_fetch_array($sql);
 
 
 
    echo $num = mysql_num_rows($sql);
 }else{
 
    echo "invalid";
 }
 
 
 
 
 
 
   mysql_close($conn);
?>

table code

--
-- Table structure for table `email`
--

CREATE TABLE IF NOT EXISTS `email` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(200) NOT NULL,
  `password` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `email`
--

INSERT INTO `email` (`id`, `email`, `password`) VALUES
(1, 'test@gmail.com', 'test'),
(2, 'teset@gmail.com', 'test');

Monday 11 May 2015

Change xampp or Wamp apache port number

Hello All,

Chnage xampp or wamp apache port number 


I am Just here Tell you How to change xampp or wamp apache port number.
Chnage xampp or wamp apache port number


In Wamp and xampp apache port in 80. 80 is it's defualt port in wamp and xampp.

so some time issue with in skyppe,sql server because then also use port 80.

if we want to use xamp and wamp port 80 then we can stop service sql sql.

and in skypee you can stop to use 80 port then follow below step

1) first goto skypee 
2) tools -> options
3)in options -> advance tab -> connection
4) Then un check the check box of use port 80 and 443 for addtions incoming connections

Change Wamp apache port number 

Step1 ) Open file "httpd.conf" with notepad++ or any editor you can use like (dream viewer,PHP designer) in  D:\wamp\bin\apache\Apache2.4.4\conf\original

Here I am Install in D Drive then my path is that. when you install wamp 
check there. "youWamp Install Drive"\wamp\bin\apache\Apache2.4.4\conf\original

Step2) After Fine use ctrl+f and find "80", the are 2 places which you need to change.

step 3) Change port 80 to be ther number, such as 88(as you wish)

step 4) After changes, restart the wamp

now listen 80 to listen 88

and servername localhost 80 to localhost:88

but make sure that new port change in httpd.conf can not use any another program.


Change Xampp apache port number 

Step1 ) Open file "httpd.conf" with notepad++ or any editor you can use like (dream viewer,PHP designer) in  E:\xampp\apache\conf

Here I am Install in E Drive then my path is that. when you install wamp 
check there. "your Xampp Install Drive"\xampp\apache\conf

Step2) After Fine use ctrl+f and find "80", the are 2 places which you need to change.

step 3) Change port 80 to be ther number, such as 88(as you wish)

step 4) After changes, restart the xampp

now listen 80 to listen 88

and servername localhost 80 to localhost:88

but make sure that new port change in httpd.conf can not use any another program.

Change xampp or Wamp apache port number

In localhost access this type locahost:88/blogger 

Give Me Comment is blog usefull or not 

Thanks






Monday 4 May 2015

Errors file upload in PHP

Hello

Here Very small errors are found in file upload.

You can find the code for file uploading from the internet  but you can make some mistake.

I Will oberserve you. mostlly mistake in file upload.

1) in form html enctype="multipart/form-data"


<form action="" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload"/>
    <input type="submit" value="Upload Image" name="submit"/>
</form>

when you use input type file then you must write enctype="multipart/form-data"
it's recuired otherwise it can not upload file or get issue or error in file upload code.

2) just check file_uploads = On in your php.ini file.

Wednesday 25 March 2015

Design anchor tag in visited link, select link, unvisited link and active link and link open in new tab


hello

you want to open in new tab then use target="_blank" propertity in anchor tab
example

http://myphpinformation.blogspot.in

anchor tag css

/* unvisited link */
a:link {
color: green;
}

/* visited link */
a:visited {
color: #776655;
}

/* mouse over link */
a:hover {
color: red;
}

/* selected link */
a:active {
color: yellow;
}
anchor tag css add in style see it.

if you want to change text-decoration in anchot tag.

text-decoration propertity by default in text-decoration: underline; if you want to remove
unader line text-decoration: none; is your css.

a:link {
color: green;
text-decoration: none;
}

if you want line in over the link then you can set as
below
a:link {
color: green;
text-decoration: overline;

}

if you want to create link line-through then change

a:link {
color: green;
text-decoration: line-through;

}

you can also change anchor tag background color;

a:link {
background-color: red;
color: #ffcc77;
text-decoration: none;
}

you can also change it font family
a:link {
background-color: red;
color: #ffcc77;
text-decoration: none;
font-family: Verdana;
}



How to get base url and go back facility in php

How to get base url and go back facility in php


Here for very normal code for that 

just get base url then you can try this code

<?php echo "http://" . $_SERVER['SERVER_NAME'] . 
$_SERVER['REQUEST_URI']; ?>

try i think it's working for you and you want create go back

<a href="#" onclick="window.history.back();">Go Back

this two for php very usefull check it suggest me.

Change connection root name, username, password and db name dynamically in PHP

Change connection root name, username, password and deb name dynamically in PHP



Hello,

I am just creating dynamically change your dbname, servername, username and password.

You can create just one file you can change your DB.

Create database blog and create a connection table in PHP my admin

Here it's code and its data

Table structure for table `connction`

CREATE TABLE IF NOT EXISTS `connction` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `localhost` varchar(200) NOT NULL,
  `username` varchar(200) NOT NULL,
  `password` varchar(200) DEFAULT NULL,
  `db_name` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

Dumping data for table `connction`

INSERT INTO `connction` (`id`, `localhost`, `username`, `password`, `db_name`) VALUES
(1, 'localhost', 'root', '', 'blog');

Wednesday 18 February 2015

how to create scroll in google spreadsheet

Set the headers in a Google Drive spreadsheet to move on the screen as I scroll down.

how to create scroll in google spreadsheet


it is easy step to create scroll in google spreadsheet

first one select cell after goto view in spread sheet after goto the freeze row then select 
(How many you want to row freeze) you can also freeze the columns(How many you want to
 columns freeze)

Monday 19 January 2015

increment decrement in php

Hello

increment decrement in php

there 4 types

1)Pre-increment:-

++$my_information  means it can be Increments $my_information by one, then returns $my_information.

2)Post-increment

$my_information++ means it can be Returns $my_information, then increments $my_information by one.

Thursday 15 January 2015

How to pass value from Javascript to php variable on the second page?

hello

How to pass value from Javascript to php variable on the second page?

I am giving example of how pass value using javascript.

create .php file like demo.php write to code

Tuesday 30 September 2014