Update Data using PHP Mysqi
<?php
if(isset($_GET['id']))
{
extract($_POST);
$con=mysqli_connect("localhost","root","root","example") or die(mysqli_error());
$query= mysqli_query($con,"select * from student_info where id='{$_GET['id']}' ") ;
//$result = mysqli_query($con,$query);
$row = mysqli_fetch_array($query);
?>
<!-- form start -->
<form id="form11" method="post">
<table align="center" border="1">
<tr>
<td>Name</td>
<td><input type="text" name="name" value="<?php echo $row['name']; ?>"></td>
</tr>
<tr>
<td>email</td>
<td><input type="email" name="email" value="<?php echo $row['email']; ?>"></td>
</tr>
<tr>
<td>address</td>
<td><textarea name="address" cols="16"><?php echo $row['address']; ?></textarea></td>
</tr>
<tr>
<td>Mobile no.</td>
<td><input type="text" name="mobile" value="<?php echo $row['m_no']; ?>"></td>
</tr>
<tr>
<td align="center">
<input type="submit" name="submit111" value="Update"/>
</td>
<td align="center">
<a href="view.php"><input type="button" name="cancel" value="cancle"/></a>
</td>
</tr>
</table>
<br />
<center>
<a href="ex1.php"><input type="button" value="Add Record"/></a>
</center>
</form>
<?php
}
?>
<?php
$con=mysqli_connect("localhost","root","root","example") or die(mysqli_error());
if(isset($_POST['submit111']))
{
extract($_POST);
$query=mysqli_query($con,"update student_info set
name='".$_POST['name']."',
email='".$_POST['email']."',
address='".$_POST['address']."',
m_no='".$_POST['mobile']."'
where id='".$_GET['id']."' ") or die(mysqli_error($con));
if($query)
{
echo '<script type="text/javascript">';
echo " alert('Record Updated');";
echo 'window.location.href = "view.php";';
echo '</script>';
}
else
{
echo '<script type="text/javascript">';
echo "alert('Eror Occured');";
die(mysqli_error($con));
echo '<script>';
//echo $cQry;
}
}
?>
if(isset($_GET['id']))
{
extract($_POST);
$con=mysqli_connect("localhost","root","root","example") or die(mysqli_error());
$query= mysqli_query($con,"select * from student_info where id='{$_GET['id']}' ") ;
//$result = mysqli_query($con,$query);
$row = mysqli_fetch_array($query);
?>
<!-- form start -->
<form id="form11" method="post">
<table align="center" border="1">
<tr>
<td>Name</td>
<td><input type="text" name="name" value="<?php echo $row['name']; ?>"></td>
</tr>
<tr>
<td>email</td>
<td><input type="email" name="email" value="<?php echo $row['email']; ?>"></td>
</tr>
<tr>
<td>address</td>
<td><textarea name="address" cols="16"><?php echo $row['address']; ?></textarea></td>
</tr>
<tr>
<td>Mobile no.</td>
<td><input type="text" name="mobile" value="<?php echo $row['m_no']; ?>"></td>
</tr>
<tr>
<td align="center">
<input type="submit" name="submit111" value="Update"/>
</td>
<td align="center">
<a href="view.php"><input type="button" name="cancel" value="cancle"/></a>
</td>
</tr>
</table>
<br />
<center>
<a href="ex1.php"><input type="button" value="Add Record"/></a>
</center>
</form>
<?php
}
?>
<?php
$con=mysqli_connect("localhost","root","root","example") or die(mysqli_error());
if(isset($_POST['submit111']))
{
extract($_POST);
$query=mysqli_query($con,"update student_info set
name='".$_POST['name']."',
email='".$_POST['email']."',
address='".$_POST['address']."',
m_no='".$_POST['mobile']."'
where id='".$_GET['id']."' ") or die(mysqli_error($con));
if($query)
{
echo '<script type="text/javascript">';
echo " alert('Record Updated');";
echo 'window.location.href = "view.php";';
echo '</script>';
}
else
{
echo '<script type="text/javascript">';
echo "alert('Eror Occured');";
die(mysqli_error($con));
echo '<script>';
//echo $cQry;
}
}
?>
Comments
Post a Comment