abc

Share This blog with your friends, so that we can improve more & more . our aim is to easy & simple way of learning.

5/23/2018

How PHP & MYSQL Related


Today we are going to learn  
1. about mqsql ,
2. how is related to php ,
3.  way of define mysql,
4.  connect & redirect data from mysql database.
Mysql is query language in which pass query & get result.
Eg: select *from student;  in this example get student table data.
As PHP is server side language & also use to handle mysql .
Let us see how to connected with mysql.
$conn = mysql_conn($host, $username, $password,  $database)
In case above example not use database then call it by mysql_db();
NOTE : MQSQLI is improved version & mysql is previous one version.
Eg: get employee information from company data
<?php
$conn = mysqli_conn(abc, kumar, welcome, company);
$q = ‘select employee name, address , age, birthdate from employee’;
$ab = mysqli_query($q, $conn) or die(‘error’);
While ($row = $mysqli_fetch_row[$ab])
{
echo $row[‘name’];
echo $row[‘address’];
echo $row[‘age’];
}
?>
Above example get all employee name , address, age. In which I use mysql_conn to connect to database & query to pass query & get result. We will see more in next session
Thanks for viewing blog send comment in case any query.

5/22/2018

How to define PHP variable & use in html


Hi,
PHP how to define variable in PHP
Generally use $ symbol to variable some cases const or global is use for global use of variable within file.
What is variable : variable is entity or say object where user can store information or use for such as number, character, string.
Eg:
$ab =100;  this is number or constant form of variable .
$ab = ‘hi’ set of character get string.
$ab =’10.256’ storing float number.
$ab =’<div><p>HI Hello how are you</p></div>’;
Above html code pass into variable so that it can easily call html or reference to number of pages.
  Eg: in one file pass php code & you need this variable to another pages , then call php
By <?php include ‘ab.php’; ?>
& <html>
<body>
<?php echo $sqrt; ?>
</body>
</html>
In above case pass variable in html code & result is in ab.php file $sqrt variable.
Suppose you are connecting to mysql database for getting data. Then call connection & get value in one variable of php file & call it in any number of file i.e. reference passing.
Simple addition program of Variable .
<?php
$a = 10 ;
$b = 50;
$c = $a +$b;
echo $c;
 ?>
In above code output is 60 a & b variable pass to c variable & echo output result.
Note: Semicolon is necessary for each line.
Thanks for viewing blog send comment in case any query.

PHP session, cookie creation & use .



Question : - How create define session variable & what is cookies how to set cookies.
Session are temporary storage variable, by using session you can get variable value in another file .
Session_start();
Session[‘ab’] = ‘hello’;
Session_close();

PHP session is easily started by call it session_start() function. this function first checks if a session is already started and if none is started then it starts one. It is recommended to put the call to session_start() at the beginning of the page.
Session variables are stored in associative array called $_SESSION[]. These variables can be accessed during lifetime of a session.
<?php
   session_start();
   if( isset( $_SESSION['ab'] ) ) {
      $_SESSION['ab'] -= 1;
   }else {
      $_SESSION['ab'] = 1;
   }
       
   $msg = "value of ab is ".  $_SESSION['ab'];
   $msg .= "in this session.";
?>

  <html>
   <head>
      <title>define session</title>
   </head>
    <body>
      <?php  echo ( $msg ); ?>
   </body>
   </html>
Similarly use session_destroy() destroy current session.
& session_close() use to close started session.
Let us see cookies , as similar to session cookies are text file to store user information.
An alert or popup message most of site are uses, eg : we are using your cookies to store information for better performance.
<?php
   setcookie("name", "mayor abc", time()+1600, "/","", 0);
   setcookie("age", "34", time()+1600, "/", "",  0);
?>
   <html>
   <head>
   <title>how to define Cookies with PHP</title>
   </head>
   <body>
      <?php echo "hi setting cookies"?>
   </body>
   </html>
In next session we see more detail.
Thanks for viewing blog send comment in case any query.

Working with HTML & PHP


Working with HTML & PHP
In this section we learn some basic of PHP :
PHP is hypertext Preprocessor .
Is server side scripting language.
While working with website : first execution of client side code then server side code.
<html>
<?php   include ‘abc.htm’; ?>
<body>
<p>hi hello</p>
</body>
</html>
In above example shows Para which execute first then fetch server side code ie abc.htm file code. If there is clear solution or clear code then all this works in 2 -3 second . remember website should load in maximum 3 -4 second or less.
HTML Code Execute first as its client side code
HTML + PHP
PHP Code server side execute
Browser display output


fig: shows how PHP Work with HTML.
Save file with .php  or .htm extension but in case html or htm need add .htaccess file to root folder.
Remember php not working directly in browser it need xampp or wamp like localhost or hosting server.
Basic syntax :
<?php
echo ‘hello world’;
?>
In above hello world is shown as output.
$ab => is variable declaration syntax. No need int or str or var like add simply put $ symbol.
Variable also used to add html code so that refer to other page  or repeated in different location.
We see more detail in next blog.
Thanks for viewing blog send comment in case any query.

An Introduction to the Laravel Framework: What It Is and Why You Should Use It

  If you're a PHP developer looking for a modern, efficient, and powerful framework to build web applications, look no further than Lara...