Select and Update data from database mysql in php
<?php include db_config.php ?>
<table width="100%" border="1">
<tr>
<td><strong><font color="#000000">Application No.</font></strong></td>
<td><strong><font color="#000000">Investor Name</font></strong></td>
<td><strong><font color="#000000">Gender</font></strong></td>
<td><strong><font color="#000000">Occuptionn</font></strong></td>
<td><strong><font color="#000000">National ID</font></strong></td>
<td><strong><font color="#000000">Mobil</font></strong></td>
<td><strong><font color="#000000">Phone</font></strong></td>
<td><strong><font color="#000000">Email</font></strong></td>
</tr>
<?PHP
$db=new mysqli(SERVER,USER,PASSWORD,DATABASE);
$sql="select * from dealer";
$rs = $db->query($sql);
while ($row = $rs->fetch_array(MYSQL_ASSOC)) {
?>
<tr>
<td><?php echo $row['Application']; ?></td>
<td><?php echo $row['Investor']; ?></td>
<td><?php echo $row['Gender']; ?></td>
<td><?php echo $row['Occuption']; ?></td>
<td><?php echo $row['NidNo']; ?></td>
<td><?php echo $row['Mobil']; ?></td>
<td><?php echo $row['Phone']; ?></td>
<td><?php echo $row['Email']; ?></td>
<td><a href="edit_dealer.php?id=<?php echo $row['id']; ?>"><strong>Edit</strong></a></td>
</tr>
<?php
}
?>
</table>
<?php include db_config.php ?>
$Id=$_GET["id"];
$db=new mysqli(SERVER,USER,PASSWORD,DATABASE);
$sql1="select id,Appdate,Application,Investor from dealer where id='$Id'";
$rs = $db->query($sql1);
$row = $rs->fetch_row();
$Appdate =$row[0];
$Application=$row[1];
$Investor=$row[2];
$FatherName=$row[3];
$MotherName=$row[4];
if(isset($_POST["btnSubmit"])){
$Appdate =$_POST["Appdate"];
$Application=$_POST["txtApplication"];
$Investor=$_POST["txtInvestor"];
$FatherName=$_POST["txtFatherName"];
$MotherName=$_POST["txtMotherName"];
$err="";
if($err==""){
$db=new mysqli(SERVER,USER,PASSWORD,DATABASE);
$sql="update dealer set Appdate='$Appdate',Application='$Application',Investor='$Investor',FatherName='$FatherName',MotherName='$MotherName' where id='$Id'";
$rs=$db->query($sql);
}else{
echo "<font color='red'><h4>$err</h4></font>" ;
}
}
?>
<form action="#" method="post">
<table>
<tr>
<td>ID</td>
<td><input type="text" name="txtId" value="<?php echo $Id? $Id:''?>" readonly style="background-color:#dddddd;" /></td>
</tr>
<tr>
<td>Date</td>
<td><input type="date" name="Appdate" value="<?php echo $Appdate? $Appdate:''?>"/></td>
</tr>
<tr>
<td>Application No.</td>
<td><input type="text" id="txtApplication" name="txtApplication" value="<?php echo $Application? $Application:''?>"/></td>
</tr>
<tr>
<td>Name of Investor</td>
<td><input type="text" id="txtInvestor" name="txtInvestor" value="<?php echo $Investor? $Investor:''?>" /></td>
</tr>
<tr>
<td>Father's Name</td>
<td><input type="text" id="txtFatherName" name="txtFatherName" value="<?php echo $FatherName? $FatherName:''?>" /></td>
</tr>
<tr>
<td>Mother's Name</td>
<td><input type="text" id="txtMotherName" name="txtMotherName" value="<?php echo $MotherName? $MotherName:''?>" /></td>
</tr>
</table>
</form>
Comments 0