-->

  • Deleting data from database by user input

     

    Deleting data from database by user input

     

     Deleting data from database by user input

     

     

    There are different programming languages currently in use, of which some are open source while others are proprietary. Open source basically refers to a program in which the source code is available to the public, free of cost, for use or for modification from its original design.

    Here we will Deleting data from database by user input for which we will use programmatic method with the help of PHP and MYSQL .

     

    Syntax of PHP


     <?php

     

     //Content goes here 

     

    ?>

     

     

     

    deletingdata.php

     

     

    <!DOCTYPE html>
    <html>
    <head>
    <title>Deleting Data</title>
    
    <style>
    
    body {
    	background: linear-gradient(to right, #1e5799 0%, #3ccdbb 20%, #16c9f6 100%);
    	
    }
    
    .form-css
    {
    	top: 50%;
    	left: 50%;
    	transform: translate(-50%, -50%);
    	position: absolute;
    	background-color: white;
    	border: 2px solid black;
    	border-radius: 20px;
    	padding: 50px;
    }
    
    
    .avatar-image img
    {
    	 justify-content: center;
    	 top: 0%;
    	 left: 50%;
    	 transform: translate(-0%, -50%);
    	position: absolute;
    	border: 1px solid black;
        border-radius: 50%;	
    	
    }
    
    button {
    	font-family: sans-serif;
    	padding: 5px;
    	cursor: pointer;
    }
    
    
    </style>
    
    
    
    
    </head>
    
    <body>
    <div class="container">
    
    <form action="controller/deletingdata-db.php" method="POST" class="form-css">
    <div class="avatar-image">
    <img src="image/avatar.png"  alt="avatar">
    </div>
    <br />
    <br />
    <label>Delete Data with ID Number</label>
    <br />
    <br />
    <input type="text" name="id" placeholder="Enter ID Number">
    <br />
    <br />
    <button type="submit" name="submit">Deleting Data</button>
    
    </form>
    </div>
    
    </body>
    </html>
    
    

     

     

     

    Then again we will create a new file called deletingdata-db.php and this file related with above the program for database as a mediator.

     

    deletingdata-db.php

     

     

    <?php
    
    
    require_once("connectionstring.php");
    
    
    $id = $_POST["id"];
    
    
    if(!$conn)
    {
    die("Connection Problem : " . mysqli_connect_error());
    }
    
    
    $sql = "Delete FROM logintable WHERE id='$id'";
    
    
    if(mysqli_query($conn, $sql))
    {
    	echo "<br>";
    	echo "<br>";
        echo "It has been deleted.";
    	echo "<br>";
    	echo "<br>";
    	echo "<a href='../gettingdata.php'>Getting Data From Database</a>";
    	echo "<br>";
    	echo "<br>";
    	echo "<a href='../deletingdata.php'>Deleting Data From Database</a>";
     
    }
    else {
    	echo "<br>";
    	echo "<br>";
        echo "Error. This name does not have an ID in our Database : " . mysqli_error($conn);
    	echo "<br>";
    	echo "<br>";
    	echo "<a href='../gettingdata.php'>Getting Data From Database</a>";
    	echo "<br>";
    	echo "<br>";
    	echo "<a href='../deletingdata.php'>Deleting Data From Database</a>";
    }
    
    
    mysqli_close($conn);
      
     
    ?>
    
    

     

     

    output

     

    Deleting data from database by user input

     

     

     

    Deleting data from database by user input

     

     

     

    Explaination




    => require_once("connectionstring") - This will produce a fatal error and stop the script.

    OR

    => include() - This will produce a warning and the script continue.



    => $conn is our new variable.


    => mysqli_connect() - The mysqli_connect() function attempts to open a connection to the MySQL Server running on host which can be either a host name or an IP address.


    Passing the NULL value or the string "localhost" or variable name to this parameter.

    Now we will check the connection whether the connection is working successfully or not!!  Actually here we will  "if and else" condition.


    => die()  - The die() function prints a message and exits the current script.


    => mysqli_connect_error() - This will produce a mysqli connection error and whats the reason of failure.


    => $sql - its a variable but in this variable we store the mysql query for select id, email
    password from table according to user input ID.



    =>  mysqli_query()
    -  mysqli_query() what it returns. The return value could be a boolean(true/false)



     

     

    Disclaimer

     

    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.

     

  • 0 comments:

    Post a Comment

    For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.