Php Code : How To Update MySQL Database Table In Php Using MySQLI

Php Code To Update Mysql Database Table Data Using MySQLI.


________________________________________________________

In this Php Tutorial we will Learn How To Update MySQL Database Table Data From Form Inputs In Php using MYSQLI.
I Use In This Tutorial:
- NetBeans IDE .
- XAMPP .
- PhpMyAdmin .


 




Php Source Code:

<?php

// php code to Update data from mysql database Table

if(isset($_POST['update']))
{
    
   $hostname = "localhost";
   $username = "root";
   $password = "";
   $databaseName = "test_db";
   
   $connect = mysqli_connect($hostname, $username, $password, $databaseName);
   
   // get values form input text and number
   
   $id = $_POST['id'];
   $fname = $_POST['fname'];
   $lname = $_POST['lname'];
   $age = $_POST['age'];
           
   // mysql query to Update data
   $query = "UPDATE `users` SET `fname`='".$fname."',`lname`='".$lname."',`age`= $age WHERE `id` = $id";
   
   $result = mysqli_query($connect, $query);
   
   if($result)
   {
       echo 'Data Updated';
   }else{
       echo 'Data Not Updated';
   }
   mysqli_close($connect);
}

?>

<!DOCTYPE html>

<html>

    <head>

        <title> PHP UPDATE DATA </title>

        <meta charset="UTF-8">

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

    </head>

    <body>

        <form action="php_update_data_from_mysql_database_table.php" method="post">

            ID To Update: <input type="text" name="id" required><br><br>

            New First Name:<input type="text" name="fname" required><br><br>

            New Last Name:<input type="text" name="lname" required><br><br>

            New Age:<input type="number" name="age" required><br><br>

            <input type="submit" name="update" value="Update Data">

        </form>

    </body>


</html>


///////////////OUTPUT:



                     
php update mysql
PHP Update




Share this

Related Posts

Previous
Next Post »

5 comments

comments
1 novembre 2016 à 18:01 delete

php_update_data_from_mysql_database_table.php
You know where can I find this file?

Reply
avatar
9 novembre 2017 à 10:31 delete

This “php ustad” tutorial blog is designed for beginners – to learn php at home step by step using simple programming examples

Reply
avatar