Jumat, 09 Oktober 2015

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

Bagikan

Jangan lewatkan

Php Code : How To Update MySQL Database Table In Php Using MySQLI
4/ 5
Oleh

Subscribe via email

Suka dengan artikel di atas? Tambahkan email Anda untuk berlangganan.