abc

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

6/10/2018

updating mysql data using php

hi in this session give detail about how update current data
for eg: name is mayur and actual in database kumar. for this purpose we use update query.
let us see,
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "employee";

// Create connection 

 $conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection 

  if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "UPDATE hello SET lastname='shahgadh' WHERE id=2";

if (mysqli_query($conn, $sql)) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . mysqli_error($conn);
}

mysqli_close($conn);
?>
in above example we see to update lastname whose id is 2 if it success then show message .
in case error pass mysqli_error in connection.

selecting data from mysql data using php

hi,
how to connect php to mysql & select data from mysql

<?php
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "abcd";

// Create connection $conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT id, firstname, lastname FROM sample";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row    while($row = mysqli_fetch_assoc($result)) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }
} else {
    echo "no record found";
}

mysqli_close($conn);
?>



in the above shows that how pass connection in above example use mysqli_num_rows & mysqli_fetch_assoc to fetching result according yo number of rows & associated result.
in this use while loop to pass all associated columns. try above example comment if any

create mysql data using php

hi toady we are going to show how to create data using php
<?php
$servername = "localhost";
$username = "root";
$password = "hello";

// Create connection 

$conn = new mysqli($servername, $username, $password);
// Check connection

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Create database

$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
    echo "Database created successfully";
} else {
    echo "Error creating database: " . $conn->error;
}

$conn->close();
?>
in this session we learn how to create database using php in mysql it may localhost or serverhost
simply pass connection , call database, display message
 

use of MYSQL in PHP

HI,
main point in this session:
1. insert data
2. create data
3. select data
4. update data
5. delete data

1. insert data
<?php
$servername = "localhost";
$username = "abcd";
$password = "blank";
$dbname = "sample";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "INSERT INTO hello(firstname, lastname, email)
VALUES ('mayur', 'kumar', 'kumar@kumar.com')";

if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>

in the above example shows that mysqli connection pass & insert data into hello table of sample database.
if record inserted then show message about record inserted sucessfully.
remaining point we discuss in next session

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...