13 March 2022

how to create custom plugin deactivate hook and display all post in wordpress?

 how to create custom plugin deactivate hook and display all post in wordpress?

make new folder in plugin after whatever you want your folder name, remember that file name and folder name same .

make folder in this folder wp-content/plugins/
exmaple : wp-content/plugins/viral/viral.php
viral is your plugin folder and viral.php is your plugin file
now add code in viral.php file.

viral.php

<?php
/**
 * @package viral
 */
/*
plugin Name: vira-plugin
plugin URI: https://vdcodin.blogspot.com/
Description: this is my custom plugin made by your name other wise details about plugin
Version: 4.1.7
Author: viral
Author URI: https://vdcodin.blogspot.com/
License: GPLv2 or later
text Domain: viral
*/
add_action('admin_menu','viral_menu');
function viral_menu(){
    add_menu_page(
        'viral', // page title
        'viral', // menu title
        'manage_options', // by-default admin site
        'dashboard', // this is called page slug
        'my_function',// callback function which we called
        'dashicons-dashboard', // this is our icon
        6      //  this is our plugin position 
    );
    //we have only one sub menu then why its showing 2?
    //lets make this one
    add_submenu_page(
        'dashboard', // parent slug beause we need submenu of this menu
        'first submenu', // page title
        'first submenu', // menu title
        'manage_options', // by-default admin site
        'dashboard', // menu slug
        'my_function' //call function which we click on sub menu and open that page      
    );
    add_submenu_page(
        'dashboard', // parent slug beause we need submenu of this menu
        'second submenu', // page title
        'second submenu', // menu title
        'manage_options', // by-default admin site
        'second-submenu', // menu slug
        'second_submenu' //call function which we click on sub menu and open that page      
    );  
    add_submenu_page(
        'dashboard', // parent slug beause we need submenu of this menu
        'third submenu', // page title
        'third submenu', // menu title
        'manage_options', // by-default admin site
        'third-submenu', // menu slug
        'third_submenu' //call function which we click on sub menu and open that page      
    );  
}
//directory
define("PLUGIN_DIR_PATH", PLUGIN_DIR_PATH(__FILE__));
function my_function(){
    include_once PLUGIN_DIR_PATH . '/include/first.php';
}
function second_submenu(){
    include_once PLUGIN_DIR_PATH . '/include/second.php';
}
function third_submenu(){
    include_once PLUGIN_DIR_PATH . '/include/third.php';
}
//now we make table and page automatically when we activat  our plugin
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
register_activation_hook(__FILE__,'table_activate');
register_activation_hook(__FILE__, 'create_page');
//deactivate hook

//drop table when plugindelete
function table_activate(){
    global $wpdb;
    $sql = "CREATE TABLE `wp_registration` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `first_name` varchar(30) NOT NULL,
        `last_name` varchar(30) NOT NULL,
        `email` varchar(30) NOT NULL,
        `password` varchar(15) NOT NULL,
        `phone_no` bigint(10) NOT NULL,
        `reg_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY (`id`)
       ) ENGINE=InnoDB DEFAULT CHARSET=latin1";
       $wpdb->query($sql);
}
// when we click on activate table made automatically when our plugin activate
//now we make our page too
function create_page()
{
    $page = array();
    $page['post_title'] = "custom page";
    $page['post_content'] = "this is our custom page when you active out plugin this page also created with plugin";
    $page['post_statud'] = "publish";
    $page['post_slug'] = "custom-page"; 
    $page['post_type'] = "page";// this slug make you choice either page or post which is ?
    $post_id = wp_insert_post($page);
    add_option("custom_plugin_page", $post_id);
    
}
register_deactivation_hook(__FILE__, 'deactivate');
//in this tutorial we deactivate our plug in and deactivate out table too.
function deactivate(){
    global $wpdb;
    $sql = "drop table wp_registration";
    $wpdb->query($sql);
}
//now we are going to fetch all our post in one page

?>

make another folder in wp-content/plugins/viral
exmaple : wp-content/plugins/viral/include
viral is your plugin folder and include is subfolder of your viral folder
now make another file in inlcude folder name first.php

example : wp-content/plugins/viral/includefirst.php

first.php

<?php 
$args = array(
    'post_type' => 'post',
    'orderby' => 'ID',
    'post_status' => 'publish', //we fetch our publish post
    'order' => 'DESC',
    'post_per_page' => -1 //here how much post you want to show
    //if you erite -1 then your all post arwe fetch if you write 2 then your  2 post are fetch
);
$result = new WP_Query($args);
if($result->have_posts()){
    while($result->have_posts()){
        $result->the_post();
        ?>
        <h1> <?php the_title(); ?></h1>
        <?php the_content(); ?>
        <?php
    }
    wp_reset_postdata();
}
else{
    echo "oh sorry for that but there have no post yet!";
}
?>


if you still confused watch my video:


video link : 

how to create custom plugin hook in wordpress?

 

how to create custom plugin  hook in wordpress?

make new folder in plugin after whatever you want your folder name, remember that file name and folder name same .

make folder in this folder wp-content/plugins/
exmaple : wp-content/plugins/viral/viral.php
viral is your plugin folder and viral.php is your plugin file
now add code in viral.php file.

viral.php

<?php
/**
 * @package viral
 */
/*
plugin Name: vira-plugin
plugin URI: https://vdcodin.blogspot.com/
Description: this is my custom plugin made by your name other wise details about plugin
Version: 4.1.7
Author: viral
Author URI: https://vdcodin.blogspot.com/
License: GPLv2 or later
text Domain: viral
*/
add_action('admin_menu','viral_menu');
function viral_menu(){
    add_menu_page(
        'viral', // page title
        'viral', // menu title
        'manage_options', // by-default admin site
        'dashboard', // this is called page slug
        'my_function',// callback function which we called
        'dashicons-dashboard', // this is our icon
        6      //  this is our plugin position 
    );
    //we have only one sub menu then why its showing 2?
    //lets make this one
    add_submenu_page(
        'dashboard', // parent slug beause we need submenu of this menu
        'first submenu', // page title
        'first submenu', // menu title
        'manage_options', // by-default admin site
        'dashboard', // menu slug
        'my_function' //call function which we click on sub menu and open that page      
    );
    add_submenu_page(
        'dashboard', // parent slug beause we need submenu of this menu
        'second submenu', // page title
        'second submenu', // menu title
        'manage_options', // by-default admin site
        'second-submenu', // menu slug
        'second_submenu' //call function which we click on sub menu and open that page      
    );  
    add_submenu_page(
        'dashboard', // parent slug beause we need submenu of this menu
        'third submenu', // page title
        'third submenu', // menu title
        'manage_options', // by-default admin site
        'third-submenu', // menu slug
        'third_submenu' //call function which we click on sub menu and open that page      
    );  
}
//directory
define("PLUGIN_DIR_PATH", PLUGIN_DIR_PATH(__FILE__));
function my_function(){
    include_once PLUGIN_DIR_PATH . '/include/first.php';
}
function second_submenu(){
    include_once PLUGIN_DIR_PATH . '/include/second.php';
}
function third_submenu(){
    include_once PLUGIN_DIR_PATH . '/include/third.php';
}
//now we make table and page automatically when we activat  our plugin
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
register_activation_hook(__FILE__,'table_activate');
register_activation_hook(__FILE__, 'create_page');
//deactivate hook

//drop table when plugindelete
function table_activate(){
    global $wpdb;
    $sql = "CREATE TABLE `wp_registration` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `first_name` varchar(30) NOT NULL,
        `last_name` varchar(30) NOT NULL,
        `email` varchar(30) NOT NULL,
        `password` varchar(15) NOT NULL,
        `phone_no` bigint(10) NOT NULL,
        `reg_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY (`id`)
       ) ENGINE=InnoDB DEFAULT CHARSET=latin1";
       $wpdb->query($sql);
}
// when we click on activate table made automatically when our plugin activate
//now we make our page too
function create_page()
{
    $page = array();
    $page['post_title'] = "custom page";
    $page['post_content'] = "this is our custom page when you active out plugin this page also created with plugin";
    $page['post_statud'] = "publish";
    $page['post_slug'] = "custom-page"; 
    $page['post_type'] = "page";// this slug make you choice either page or post which is ?
    $post_id = wp_insert_post($page);
    add_option("custom_plugin_page", $post_id);
    
}

if you still confused watch my video:


how to create custom plugin dir in wordpress?

 

how to create custom plugin  submenu in wordpress?

make new folder in plugin after whatever you want your folder name, remember that file name and folder name same .

make folder in this folder wp-content/plugins/
exmaple : wp-content/plugins/viral/viral.php
viral is your plugin folder and viral.php is your plugin file
now add code in viral.php file.

viral.php


<?php
/**
 * @package viral
 */
/*
plugin Name: vira-plugin
plugin URI: https://vdcodin.blogspot.com/
Description: this is my custom plugin made by your name other wise details about plugin
Version: 4.1.7
Author: viral
Author URI: https://vdcodin.blogspot.com/
License: GPLv2 or later
text Domain: viral
*/
add_action('admin_menu','viral_menu');
function viral_menu(){
    add_menu_page(
        'viral', // page title
        'viral', // menu title
        'manage_options', // by-default admin site
        'dashboard', // this is called page slug
        'my_function',// callback function which we called
        'dashicons-dashboard', // this is our icon
        6      //  this is our plugin position 
    );
    //we have only one sub menu then why its showing 2?
    //lets make this one
    add_submenu_page(
        'dashboard', // parent slug beause we need submenu of this menu
        'first submenu', // page title
        'first submenu', // menu title
        'manage_options', // by-default admin site
        'dashboard', // menu slug
        'my_function' //call function which we click on sub menu and open that page      
    );
    add_submenu_page(
        'dashboard', // parent slug beause we need submenu of this menu
        'second submenu', // page title
        'second submenu', // menu title
        'manage_options', // by-default admin site
        'second-submenu', // menu slug
        'second_submenu' //call function which we click on sub menu and open that page      
    );  
    add_submenu_page(
        'dashboard', // parent slug beause we need submenu of this menu
        'third submenu', // page title
        'third submenu', // menu title
        'manage_options', // by-default admin site
        'third-submenu', // menu slug
        'third_submenu' //call function which we click on sub menu and open that page      
    );  
}
//directory
define("PLUGIN_DIR_PATH", PLUGIN_DIR_PATH(__FILE__));
function my_function(){
    include_once PLUGIN_DIR_PATH . '/include/first.php';
}
function second_submenu(){
    include_once PLUGIN_DIR_PATH . '/include/second.php';
}
function third_submenu(){
    include_once PLUGIN_DIR_PATH . '/include/third.php';
}

if you still confused watch my video:


how to create custom plugin submenu in wordpress?

 how to create custom plugin  submenu in wordpress?

make new folder in plugin after whatever you want your folder name, remember that file name and folder name same .

make folder in this folder wp-content/plugins/
exmaple : wp-content/plugins/viral/viral.php
viral is your plugin folder and viral.php is your plugin file
now add code in viral.php file.

viral.php

<?php
/**
 * @package viral
 */
/*
plugin Name: vira-plugin
plugin URI: https://vdcodin.blogspot.com/
Description: this is my custom plugin made by your name other wise details about plugin
Version: 4.1.7
Author: viral
Author URI: https://vdcodin.blogspot.com/
License: GPLv2 or later
text Domain: viral
*/
add_action('admin_menu','viral_menu');
function viral_menu(){
    add_menu_page(
        'viral', // page title
        'viral', // menu title
        'manage_options', // by-default admin site
        'dashboard', // this is called page slug
        'my_function',// callback function which we called
        'dashicons-dashboard', // this is our icon
        6      //  this is our plugin position 
    );
    //we have only one sub menu then why its showing 2?
    //lets make this one
    add_submenu_page(
        'dashboard', // parent slug beause we need submenu of this menu
        'first submenu', // page title
        'first submenu', // menu title
        'manage_options', // by-default admin site
        'dashboard', // menu slug
        'my_function' //call function which we click on sub menu and open that page      
    );
    add_submenu_page(
        'dashboard', // parent slug beause we need submenu of this menu
        'second submenu', // page title
        'second submenu', // menu title
        'manage_options', // by-default admin site
        'second-submenu', // menu slug
        'second_submenu' //call function which we click on sub menu and open that page      
    );  
    add_submenu_page(
        'dashboard', // parent slug beause we need submenu of this menu
        'third submenu', // page title
        'third submenu', // menu title
        'manage_options', // by-default admin site
        'third-submenu', // menu slug
        'third_submenu' //call function which we click on sub menu and open that page      
    );  
}



if you still confused watch my video:








how to create custom plugin menu in wordpress?

 custom plugin  menu and in wordpress?

make new folder in plugin after whatever you want your folder name, remember that file name and folder name same .

make folder in this folder wp-content/plugins/
exmaple : wp-content/plugins/viral/viral.php
viral is your plugin folder and viral.php is your plugin file
now add code in viral.php file.

viral.php

<?php
/**
 * @package viral
 */
/*
plugin Name: vira-plugin
plugin URI: https://vdcodin.blogspot.com/
Description: this is my custom plugin made by your name other wise details about plugin
Version: 4.1.7
Author: viral
Author URI: https://vdcodin.blogspot.com/
License: GPLv2 or later
text Domain: viral
*/
add_action('admin_menu','viral_menu');
function viral_menu(){
    add_menu_page(
        'viral', // page title
        'viral', // menu title
        'manage_options', // by-default admin site
        'dashboard', // this is called page slug
        'my_function',// callback function which we called
        'dashicons-dashboard', // this is our icon
        6      //  this is our plugin position 
    );
}

if you still confused watch my video:

how to create custom plugin in wordpress?

 custom plugin in wordpress?


make new folder in plugin after whatever you want your folder name, remember that file name and folder name same .

make folder in this folder wp-content/plugins/
exmaple : wp-content/plugins/viral/viral.php
viral is your plugin folder and viral.php is your plugin file
now add code in viral.php file


viral.php

  <?php
/**
 * @package viral
 */
/*
plugin Name: vira-plugin
plugin URI: https://vdcodin.blogspot.com/
Description: this is my custom plugin made by your name other wise details about plugin
Version: 4.1.7
Author: viral
Author URI: https://vdcodin.blogspot.com/
License: GPLv2 or later
text Domain: viral
*/

if you still confused watch my video:





how to make custom widget in wordpress?

custom widget in wordpress?

add this code on your function.php file the last one viral-widget we added for out custom widget
function electo_store_widgets_init() {
register_sidebar( array(
'name'          => __( 'Blog Sidebar', 'electo-store' ),
'description'   => __( 'Appears on posts and pages', 'electo-store' ),
'id'            => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget'  => '</aside>',
'before_title'  => '<h3 class="widget-title">',
'after_title'   => '</h3>',
) );

register_sidebar( array(
'name'          => __( 'Posts and Pages Sidebar', 'electo-store' ),
'description'   => __( 'Appears on posts and pages', 'electo-store' ),
'id'            => 'sidebar-2',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget'  => '</aside>',
'before_title'  => '<h3 class="widget-title">',
'after_title'   => '</h3>',
) );
register_sidebar( array(
'name'          => __( 'Third Column Sidebar', 'electo-store' ),
'description'   => __( 'Appears on posts and pages', 'electo-store' ),
'id'            => 'sidebar-3',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget'  => '</aside>',
'before_title'  => '<h3 class="widget-title">',
'after_title'   => '</h3>',
) );
//Footer widget areas
$electo_store_widget_areas = get_theme_mod('footer_widget_areas', '4');
for ($i=1; $i<=$electo_store_widget_areas; $i++) {
register_sidebar( array(
'name'          => __( 'Footer Widget ', 'electo-store' ) . $i,
'id'            => 'footer-' . $i,
'description'   => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget'  => '</aside>',
'before_title'  => '<h3 class="widget-title">',
'after_title'   => '</h3>',
) );
}
register_sidebar( array(
'name'          => __( 'viral widget', 'electo-store' ),
'description'   => __( 'add custom menu for diplay name', 'electo-store' ),
'id'            => 'viral-widget',
'before_widget' => '',
'after_widget'  => '',
'before_title'  => '<h3 class="widget-title">',
'after_title'   => '</h3>',
) );

}

function.php file

register_sidebar( array(
'name'          => __( 'viral widget', 'electo-store' ),
'description'   => __( 'add custom menu for diplay name', 'electo-store' ),
'id'            => 'viral-widget',
'before_widget' => '',
'after_widget'  => '',
'before_title'  => '<h3 class="widget-title">',
'after_title'   => '</h3>',
) );


whenever you want diplay your code in wordpress add this code on your header.php  or footer.php file.

use div tag if you want to.

header or footer.php file

<?php dynamic_sidebar('viral-widget'); ?>

watch our video if you have any doubt :

04 March 2022

Crud Operation in php?

    how to perform Crud Operation in php?

Guide:

After a database and a table have been created,we can start insert records in it.
after all you need to insert record in data base using the form of html and php.
for insert record you need some html code ane insert query.
you need three pages

table Query: 

CREATE TABLE `register` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(30) NOT NULL,

  `email` varchar(30) NOT NULL,

  `password` varchar(30) NOT NULL,

  `mobileno` bigint(10) NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4

how to insert record ?

remove if condition  and update query which i mention in this page

like>if (isset($_POST["insert"])) {

    include("config.php");

    $name = $_POST["txtname"];

    $email = $_POST["txtemail"];

    $pwd = $_POST["txtpass"];

    $mobile = $_POST["txtmobile"];

    $sql = "INSERT INTO register VALUES('', '$name','$email','$pwd','$mobile')";

    $result = mysqli_query($conn, $sql);

    if ($result) {

        header("location:showdata.php");

    }

}

for insert record and you can also add another button for update and another isset function for update,

but here i did it on one button

when id is null it happen insert operation,

and when my id is not null it happens update operation.



config.php page

<?php
// for connection
$conn = mysqli_connect("localhost","root","","demo1");
if(!$conn){
    echo "connection error";
}
?>

index.php page

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

</head>

<body>

    <form action="" method="post">

        <?php 

    if(isset($_REQUEST["eid"])){

        include("config.php");

        $id = $_REQUEST["eid"];

        $sql = "SELECT * FROM registration WHERE id = $id";

        $ins = mysqli_query($conn,$sql);

        $row = mysqli_fetch_row($ins);

        }

        ?>

    <table>

        <tr>

            <!-- name is on number 1 position -->

            <td>Name</td>

            <td><input type="text" name="txtname" value="<?php echo @$row[1]; ?>"></td>

        </tr>

        <tr>

            <td>Email</td>

            <td><input type="email" name="txtemail" value="<?php echo @$row[2]; ?>"></td>

        </tr>

        <tr>

            <td>Password :</td>

            <td><input type="password" name="txtpwd" value="<?php echo @$row[3]; ?>"></td>

        </tr>

        <tr>

            <td>Mobile No :</td>

            <td><input type="text" name="txtmo" value="<?php echo @$row[4]; ?>"></td>

        </tr>

        <tr>

            <td><input type="submit" name="submit" value="submit"></td>

            <td><a href="display.php">display record</a></td>

        </tr>

    </table>

    </form>

</body>

</html>

<?php

if(isset($_POST["submit"])){

    include("config.php");

    $name = $_POST["txtname"];

    $email = $_POST["txtemail"];

    $pwd = $_POST["txtpwd"];

    $mono = $_POST["txtmo"];

    $id = $_REQUEST["eid"];

    if($id == null){

    $sql = "INSERT INTO registration VALUES('','$name','$email','$pwd','$mono')";

}else{

    $sql = "UPDATE registration SET name = '$name',email = '$email',password = '$pwd',mobileno = '$mono' WHERE id = $id";

}

    $result = mysqli_query($conn,$sql);

    if($result){

        header("location:display.php");

    }

}

?>


how to display data in our page?

The second operation is  used to display or read the data that is already available in the database.



display.php page

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

</head>

<body>

    <form action="" method="post">

    <table border="2px solid black">

        <tr>

            <td><a href="index.php">home</a></td>

        </tr>

        <tr>

            <td>ID</td>

            <td>NAME</td>

            <td>EMAIL</td>

            <td>PASSWORD</td>

            <td>MOBILENO</td>

            <td>EDIT</td>

            <td>DELETE</td>

        </tr>

        <?php

    include("config.php");

    $sql = "SELECT * FROM registration";

    $ins = mysqli_query($conn,$sql);

    if(mysqli_num_rows($ins) > 0){

    while($row = mysqli_fetch_row($ins)){

    ?>

    <tr>

        <td><?php echo $row[0]; ?></td>

        <td><?php echo $row[1]; ?></td>

        <td><?php echo $row[2]; ?></td>

        <td><?php echo $row[3]; ?></td>

        <td><?php echo $row[4]; ?></td>

        <td><a href="index.php?eid=<?php echo $row[0]; ?>">edit</a></td>

        <td><a href="display.php?eid=<?php echo $row[0]; ?>">delete</a></td>

    </tr>

<?php

    }

}else{

    echo "no data found";

}

        ?>

    </table>

    </form>

</body>

</html>

<?php

if(isset($_REQUEST["eid"])){

    include("config.php");

    $id = $_REQUEST["eid"];

    $sql = "DELETE FROM registration WHERE id = $id";

    $ins = mysqli_query($conn,$sql);

    if($ins){

    header("location:display.php");

    }

}

?>

if you still dont understand look our video 




02 March 2022

how to delete data in php?

 

 delete data  in php?

Guide:
After a database and a table have been created,we can start insert records in it.
after  insert record you need to delete record using the form of html and php.
for insert record you need some html code ane insert query.
you need three pages.

table Query: 

CREATE TABLE `register` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(30) NOT NULL,

  `email` varchar(30) NOT NULL,

  `password` varchar(30) NOT NULL,

  `mobileno` bigint(10) NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4


how to insert or update  and delete record ?

here i use one condition for check id is null or not.
if id is null than it perform insert query, otherwise it perform update query.

simply fetch id for deleting records.

index.php page


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form method="post">
        <?php
        if (isset($_REQUEST["eid"])) {
            include("config.php");
            $id = $_REQUEST["eid"];
            $sql = "select * from register where id = $id";
            $ins = mysqli_query($conn, $sql);
            $row = mysqli_fetch_row($ins);
        }
        ?>
        <table>
            <tr>
                <td>Name</td>
                <td><input type="text" name="txtname" value="<?php echo @$row[1]; ?>"></td>
            </tr>
            <tr>
                <td>Email</td>
                <td><input type="email" name="txtemail" value="<?php echo @$row[2]; ?>"></td>
            </tr>
            <tr>
                <td>Password</td>
                <td><input type="pass" name="txtpass" value="<?php echo @$row[3]; ?>"></td>
            </tr>
            <tr>
                <td>Mobile No</td>
                <td><input type="text" name="txtmobile" value="<?php echo @$row[4]; ?>"></td>
            </tr>
            <tr>
                <td><input type="submit" name="insert" value="insert"></td>
                <td> <a href="showdata.php">show data</a></td>
            </tr>
        </table>
    </form>
</body>
</html>
<?php
if (isset($_POST["insert"])) {
    include("config.php");

    $name = $_POST["txtname"];
    $email = $_POST["txtemail"];
    $pwd = $_POST["txtpass"];
    $mobile = $_POST["txtmobile"];
    $id = $_REQUEST["eid"];
    if ($id == null) {
        $sql = "INSERT INTO register VALUES('', '$name','$email','$pwd','$mobile')";
    } else {
        $sql = "UPDATE register SET name = '$name',email='$email',password='$pwd',mobileno='$mobile' WHERE id = $id";
    }
    $result = mysqli_query($conn, $sql);
    if ($result) {
        header("location:showdata.php");
    }
}
?>


how to display data in our page?

The second operation is  used to display or read the data that is already available in the database.

here i fetch id from link  name edit

it will redirect to indexpage with id.

showdata.php page

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

</head>


<body>

    <form action="" method="post">

        <?php

        if (isset($_REQUEST["eid"])) {

            include("config.php");

            $id = $_REQUEST["eid"];

            $sql = "select * from register where id = $id";

            $ins = mysqli_query($conn, $sql);

            $row = mysqli_fetch_row($ins);

        }

        ?>

        <table>

            <tr>

                <td><a href="index.php">add</a>

                </td>

            </tr>

        </table>

        <table border="2px">

            <tr>

                <td>id</td>

                <td>name</td>

                <td>email</td>

                <td>password</td>

                <td>mobileno</td>

                <td>edit</td>

               

            </tr>

            <?php

            include("config.php");

            $sql = "SELECT * FROM register";

            $ins = mysqli_query($conn, $sql);

            while ($row = mysqli_fetch_row($ins)) {

            ?>

                <tr>

                    <td><?php echo $row[0]; ?> </td>

                    <td><?php echo $row[1]; ?> </td>

                    <td><?php echo $row[2]; ?> </td>

                    <td><?php echo $row[3]; ?> </td>

                    <td><?php echo $row[4]; ?> </td>

                    <td><a href="index.php?eid=<?php echo $row[0]; ?>">edit</a></td>

 <td><a href="showdata.php?did=<?php echo $row[0]; ?>">delete</a></td>

                               </tr>

            <?php

            }

            ?>

        </table>

        <table>

            <tr>

                <td><a href="index.php">add</a></td>

            </tr>

        </table>

    </form>

</body>

</html>


<?php

if (isset($_REQUEST["did"])) {

    include("config.php");

    $id = $_REQUEST["did"];

    $sql = "DELETE FROM registration     WHERE id = $id ";

    $ins = mysqli_query($conn, $sql);

    header("location:showdata.php");

}

?>

config.php page

<?php

$conn = mysqli_connect("localhost", "root", "", "viral");

?>

if you still consude under code please watch our video and clear your concept:




How to update data in php?

 update data  in php?

Guide:
After a database and a table have been created,we can start insert records in it.
after  insert record you need to update record using the form of html and php.
for insert record you need some html code ane insert query.
you need two pages.

table Query: 

CREATE TABLE `register` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(30) NOT NULL,

  `email` varchar(30) NOT NULL,

  `password` varchar(30) NOT NULL,

  `mobileno` bigint(10) NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4


how to insert or update record ?

here i use one condition for check id is null or not.
if id is null than it perform insert query, otherwise it perform update query.

index.php page


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form method="post">
        <?php
        if (isset($_REQUEST["eid"])) {
            include("config.php");
            $id = $_REQUEST["eid"];
            $sql = "select * from register where id = $id";
            $ins = mysqli_query($conn, $sql);
            $row = mysqli_fetch_row($ins);
        }
        ?>
        <table>
            <tr>
                <td>Name</td>
                <td><input type="text" name="txtname" value="<?php echo @$row[1]; ?>"></td>
            </tr>
            <tr>
                <td>Email</td>
                <td><input type="email" name="txtemail" value="<?php echo @$row[2]; ?>"></td>
            </tr>
            <tr>
                <td>Password</td>
                <td><input type="pass" name="txtpass" value="<?php echo @$row[3]; ?>"></td>
            </tr>
            <tr>
                <td>Mobile No</td>
                <td><input type="text" name="txtmobile" value="<?php echo @$row[4]; ?>"></td>
            </tr>
            <tr>
                <td><input type="submit" name="insert" value="insert"></td>
                <td> <a href="showdata.php">show data</a></td>
            </tr>
        </table>
    </form>
</body>
</html>
<?php
if (isset($_POST["insert"])) {
    include("config.php");

    $name = $_POST["txtname"];
    $email = $_POST["txtemail"];
    $pwd = $_POST["txtpass"];
    $mobile = $_POST["txtmobile"];
    $id = $_REQUEST["eid"];
    if ($id == null) {
        $sql = "INSERT INTO register VALUES('', '$name','$email','$pwd','$mobile')";
    } else {
        $sql = "UPDATE register SET name = '$name',email='$email',password='$pwd',mobileno='$mobile' WHERE id = $id";
    }
    $result = mysqli_query($conn, $sql);
    if ($result) {
        header("location:showdata.php");
    }
}
?>


how to display data in our page?

The second operation is  used to display or read the data that is already available in the database.

here i fetch id from link  name edit

it will redirect to indexpage with id.

showdata.php page

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

</head>


<body>

    <form action="" method="post">

        <?php

        if (isset($_REQUEST["eid"])) {

            include("config.php");

            $id = $_REQUEST["eid"];

            $sql = "select * from register where id = $id";

            $ins = mysqli_query($conn, $sql);

            $row = mysqli_fetch_row($ins);

        }

        ?>

        <table>

            <tr>

                <td><a href="index.php">add</a>

                </td>

            </tr>

        </table>

        <table border="2px">

            <tr>

                <td>id</td>

                <td>name</td>

                <td>email</td>

                <td>password</td>

                <td>mobileno</td>

                <td>edit</td>

               

            </tr>

            <?php

            include("config.php");

            $sql = "SELECT * FROM register";

            $ins = mysqli_query($conn, $sql);

            while ($row = mysqli_fetch_row($ins)) {

            ?>

                <tr>

                    <td><?php echo $row[0]; ?> </td>

                    <td><?php echo $row[1]; ?> </td>

                    <td><?php echo $row[2]; ?> </td>

                    <td><?php echo $row[3]; ?> </td>

                    <td><?php echo $row[4]; ?> </td>

                    <td><a href="index.php?eid=<?php echo $row[0]; ?>">edit</a></td>

                               </tr>

            <?php

            }

            ?>

        </table>

        <table>

            <tr>

                <td><a href="index.php">add</a></td>

            </tr>

        </table>

    </form>

</body>

</html>

config.php page

<?php

$conn = mysqli_connect("localhost", "root", "", "viral");

?>

if you still consude under code please watch our video and clear your concept:



how to disply data in php?

 how to disply data in php?

Guide:
After a database and a table have been created,we can start insert records in it.
after all you need to insert record in data base using the form of html and php.
for insert record you need some html code ane insert query.
you need two pages.

table Query: 

CREATE TABLE `register` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(30) NOT NULL,

  `email` varchar(30) NOT NULL,

  `password` varchar(30) NOT NULL,

  `mobileno` bigint(10) NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4

how to insert record ?

index.php page

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

</head>

<body>

    <form method="post">

               <table>

            <tr>

                <td>Name</td>

                <td><input type="text" name="txtname" value="<?php echo @$row[1]; ?>"></td>

            </tr>

            <tr>

                <td>Email</td>

                <td><input type="email" name="txtemail" value="<?php echo @$row[2]; ?>"></td>

            </tr>

            <tr>

                <td>Password</td>

                <td><input type="pass" name="txtpass" value="<?php echo @$row[3]; ?>"></td>

            </tr>

            <tr>

                <td>Mobile No</td>

                <td><input type="text" name="txtmobile" value="<?php echo @$row[4]; ?>"></td>

            </tr>

            <tr>

                <td><input type="submit" name="insert" value="insert"></td>

                <td> <a href="showdata.php">show data</a></td>

            </tr>

        </table>

    </form>

</body>

</html>

<?php

if (isset($_POST["insert"])) {

    include("config.php");

    $name = $_POST["txtname"];

    $email = $_POST["txtemail"];

    $pwd = $_POST["txtpass"];

    $mobile = $_POST["txtmobile"];

        $sql = "INSERT INTO register VALUES('', '$name','$email','$pwd','$mobile')";

       $result = mysqli_query($conn, $sql);

    if ($result) {

        header("location:showdata.php");

    }

}

?>

how to display data in our page?

The second operation is  used to display or read the data that is already available in the database.


showdata.php page

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="" method="post">
 
        <table>
            <tr>
                <td><a href="index.php">add</a>
                </td>
            </tr>
        </table>
        <table border="2px">
            <tr>
                <td>id</td>
                <td>name</td>
                <td>email</td>
                <td>password</td>
                <td>mobileno</td>
                <td>edit</td>
                <td>delete</td>
            </tr>
            <?php
            include("config.php");
            $sql = "SELECT * FROM register";
            $ins = mysqli_query($conn, $sql);
            while ($row = mysqli_fetch_row($ins)) {
            ?>
                <tr>
                    <td><?php echo $row[0]; ?> </td>
                    <td><?php echo $row[1]; ?> </td>
                    <td><?php echo $row[2]; ?> </td>
                    <td><?php echo $row[3]; ?> </td>
                    <td><?php echo $row[4]; ?> </td>
             
                </tr>
            <?php
            }
            ?>
        </table>
        <table>
            <tr>
                <td><a href="index.php">add</a></td>
            </tr>
        </table>
    </form>
</body>
</html>


config.php page
<?php
$conn = mysqli_connect("localhost", "root", "", "viral");
?>

if you still dont understand code please watch our video :



how to create custom plugin deactivate hook and display all post in wordpress?

 how to create custom plugin deactivate hook and display all post in wordpress? make new folder in plugin after whatever you want your folde...