PHP Update Row/Values in Database

Till now in  the previous Tutorials we have   retrieved , inserted , deleted few values in database with the help of php which is available here .

 In this Section We are going to update row of database with the help of  PHP . Now Lets do Practical:

Step 1: First of all start your wamp/xampp server and open phpmyadmin tool For this open  http://localhost/phpmyadmin  in your browser.

Step 2: Second  click on SQL tab and create a database  named testdb1 and insert two values in it with following script :-

create database testdb;
use  testdb;
create table members(id int primary key auto_increment,name varchar(100),email varchar(200),password varchar(100));
insert into members(name,email,password)values('raggu','raggu@gmail.com','1234'),
('hardik','hardik@gmail.com','1234');

Step 3:create a new php document and name it as user_update.php and save it in server root , in case using wamp save it in www directory or in htdoc when using xampp.

Step 4: write following code in user_update.php.

<?php
$conn=mysqli_connect('localhost','root','','testdb');
$sql="update members set name='Raghu',
email='raghu@gmail.com',password='raghu1234' where id='2'";
$success=mysqli_query($conn,$sql);
if($success)echo"Member Updated successfully";
?>

Step 5 : open browser and see output http://localhost/user_update.php


No comments:

| Designed by Harhiktech