Friday, 21 February 2014

How To Update Your Record Using PHP code ???

Update Records Using PHP + MySQL 

          If Any One wants to update his/her profile then he/she must have to login for that.
And according to their username and password the profile management is done.

Here is the code for any programmer or developer who want's to manage users and admins from their website.
1. First of all he/she have to see all the records of the table 
2. then select any record to update
3. After updating the record he/she must have to see updated record with all other records.

Table Name of MySQL is tbladmin_reg
Have columns
1. id
2. fullname
3. userid
4. password
5. emailid
6. mobileno

Here is the full code for admin registration1. show details


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Show Registration Details </title>
<link rel="stylesheet" href="table.css" type="text/css">
<?php
include('dbconnection.php');
$sql="select * from tbladmin_reg";
$result=mysqli_query($con,$sql);
echo "<center>";
echo "<h1> SHOW REGISTRATION FORM </h1>";
echo "<table width='90%'>";
echo "<tr>";
echo "<th> ID NO. </th>";
echo "<th> FULL NAME </th>";
echo "<th> USER ID </th>";
echo "<th> PASSWORD </th>";
echo "<th> Email ID </th>";
echo "<th> MOBILE NO </th>";
echo "</tr>";

while($line=mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>";
echo $line['id'];
echo "</td>";
echo "<td>";
echo $line['fullname'];
echo "</td>";
echo "<td>";
echo $line['userid'];
echo "</td>";
echo "<td>";
echo $line['password'];
echo "</td>";

echo "<td>";
echo $line['emailid'];
echo "</td>";

echo "<td>";
echo $line['mobileno'];
echo "</td>";
$id=$line['id'];
echo "<td>";
echo "<a href=\"updatereg.php?id=$id\">Edit</a>";
echo "</td>";
echo "</tr>";
}
?>
</head>

<body>
</body>
</html>

2. 
And here is the code for updatereg.php file
updatereg.php

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Update Record</title>
</head>
<?php
$id=$_REQUEST['id'];
include('dbconnection.php');
$sql="select * from tbladmin_reg where `id`='$id'";
$result=mysqli_query($con,$sql) or die("Database table error");
echo "<center>";
echo "<h1> Update Record </h1>";
echo "<table width='90%'>";
echo "<tr><td>FullName</td><td>";
while($line=mysqli_fetch_assoc($result))
{
?>

<body>
<form id="form1" name="form1" method="post" action="" />
<input type="text" name="fullname" value="<?php echo $line['fullname']; ?>" />
<?php
echo "</td></tr><tr><td>UserID</td><td>";
?>
<input type="text" name="username" value="<?php echo $line['userid']; ?>" />

<?php
echo "</td></tr><tr><td>EmailID</td><td>";
?>
<input type="text" name="emailid" value="<?php echo $line['emailid']; ?>" />
<?php
echo "</td></tr><tr><td>Mobileno</td><td>";
?>
<input type="text" name="mobileno" value="<?php echo $line['mobileno']; ?>" />

<?php
echo "</td></tr><tr><td></td><td>";
?>

<?php
echo "</td></tr></table>";
}
?>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if(isset($_POST['submit']))
{
$id=$_REQUEST['id'];
$ui=$_POST['username'];
$fn=$_POST['fullname'];
$ei=$_POST['emailid'];
$mn=$_POST['mobileno'];

include('dbconnection.php');
$sql="update tbladmin_reg set `userid`='$ui',`fullname`='$fn',`emailid`='$ei',`mobileno`='$mn' where `id`='$id'";
$result=mysqli_query($con,$sql) or die("Database table error");
echo "Record Updated Successfully!!!";

}
?>   
</body>
</html>

3 comments:

  1. If you are creating a web portal with core php code then this post will be very helpful to you.

    Thanks And Regards,
    Hitesh Vataliya.

    ReplyDelete
  2. Learn PHP Project with MySQL
    visit website : http://www.vataliyatuitionclasses.com

    ReplyDelete
  3. Full stack web development, MEAN stack web development, MERN stack web development, visit our official website: http://www.vataliyacomputer.in

    ReplyDelete