How to Update Data into Database using PHP

How to Update Data into Database using PHP

Today we will guide you How to Update Data into Database using PHP and MySQL.

index.php

<html>
<head>
<title>Update Data</title>
</head>
<body>
<form method="post" action="update.php" enctype="multipart/form-data">
<div class="name">
	<div class="name1"><h1>Student Name:</h1></div>
	<div class="name2"><input type="text" name="name" value="<?php echo $row['name']; ?>" /></div>
</div>
<div class="name">
	<div class="name1"><h1>Father Name:</h1></div>
	<div class="name2"><input type="text" name="father_name" value="<?php echo $row['father_name']; ?>" /></div>
</div>
<div class="name">
	<div class="name1"><h1>Mother Name:</h1></div>
	<div class="name2"><input type="text" name="mother_name" value="<?php echo $row['mother_name']; ?>" /></div>
</div>
<div class="name">
    <div class="name1"><h1>E-mail:</h1></div>
    <div class="name2"><input type="email" name="email" value="<?php echo $row['e_mail']; ?>"  /></div>
</div>
<div class="name">
    <div class="name1"><h1>Address:</h1></div>
    <div class="name2"><textarea name="address"><?php echo $row['address']; ?> </textarea></div>
</div>
<div class="name">
	<div class="name1"><h2>DOB:</h2></div>
    <div class="name2"><input type="text" class="inp" name="dob" value="<?php echo $row['dob']; ?>"  /></div>
</div>
<div class="name">
	<div class="name1"><h2>Category:</h2></div>
	<div class="name3"><input type="radio" name="gender" value="male" <?php if($row['category']== 'male' ) { ?> checked="checked" <?php } ?>/></div><h2 class="cat">male</h2>
    <div class="name3"><input type="radio" name="gender" value="female" <?php if($row['category']== 'female' ) { ?> checked="checked" <?php } ?>/></div><h2 class="cat">female</h2>
</div>
<div class="name">
	<div class="name1"><h2>Course:</h2></div>
    <div class="name4"><select name="course">
    							<option value="<?php echo $row['courses']; ?>"><?php echo $row['courses']; ?></option>
    							<option value="BCA">BCA</option>
                                <option value="MCA">MCA</option>
                                <option value="BBA">BBA</option>
                                <option value="DCA">DCA</option>
    					</select></div>
</div>

    <input type="submit" class="sub" name="sub" value="Submit"  />
</form>
</body></html>

style.css

.name{
width:100%;
min-height:30px;
height:auto;
float:left;
margin-bottom:20px;
}
.name1{
width:14%;
min-height:20px;
float:left;
height:auto;
}
.name1 h1{
font-size:18px;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
.name1 h2{
font-size:18px;
font-family:Verdana, Arial, Helvetica, sans-serif;
margin-top:55px;
}
.name2{
width:30%;
height:30px;
float:left;
}
.name input{
margin-top:10px;
height:25px;
width:50%;
border:#999999 1px solid;
border-radius:5px;
}
.name textarea{
margin-top:10px;
height:70px;
width:50%;
border:#999999 1px solid;
border-radius:5px;
}
.name2 input.inp{
margin-top:50px;
}
.sub{
margin-top:50px;
margin-left:120px;
}
.name3{
width:3%;
height:30px;
float:left;
margin-top:45px;
}
.cat{
float:left;
font-size:20px;
margin-top:55px;
}
.name4{
width:3%;
height:30px;
float:left;
margin-top:60px;
}

update.php

<?php
include(db.php);
$id = $_GET['id'];
if(isset($_POST['sub']) == 'Submit'){
$name = $_POST['name'];                                          // from input name/value
$father_name = $_POST['father_name'];
$mother_name = $_POST['mother_name'];
$e_mail = $_POST['email'];
$add = $_POST['address'];
$dob = $_POST['dob'];
$category = $_POST['gender'];
$courses = $_POST['course'];
$query = "update new set name='$name', father_name='$father_name', mother_name='$mother_name', address='$add', dob='$dob', e_mail='$e_mail', courses='$courses',   category='$category' where id = '$id'";                                             // from database
$num=mysql_query($query);
}
$query1 = "select * from new where id = '$id' ";
$query2 = mysql_query($query1);
$row = mysql_fetch_array($query2);
echo "<pre>";print_r($row);echo "</pre> <br>";
?>

db.php

<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('db');
?>

5 Comments

  • Arnoldo

    September 11, 2020 - 7:01 pm

    I’m really enjoying the design and layout of your website.

    It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a
    designer to create your theme? Exceptional work!

  • CustomissSpace

    April 9, 2020 - 11:26 pm

    Check out our customized gifts selection for the very best in unique or custom, handmade pieces from our shops.
    Click to send a Digital Gift to Your Loved Ones.
    https://customiss.com

  • labedroomTwins

    April 8, 2020 - 10:10 am

    King bedroom sets
    On site online our store customer waiting huge choice at price. Our catalog contains retail prices, white wooden bed information about types fittings permissible types complete modules. Absolutely any item office and home furniture supplied directly from manufacturer. Lowering cost on king size supplements formed based on the absence of trade trading floors, for hiring which necessary pay and smallest staff workers. No such costs provide the opportunity to establish very affordable prices for every buyer for all groups acquisitions.

  • How to Insert Data into Mysql Database using PHP - Hub of Tutorials

    March 17, 2020 - 1:22 pm

    […] How to Update Data into Database using PHP […]

  • How to Fetch Data From Mysql Database using PHP - Hub of Tutorials

    March 17, 2020 - 1:20 pm

    […] How to Update Data into Database using PHP […]

Leave A Reply