Saturday, 18 August 2018

UPDATE

6. update.php

<?php
include('db.php');
$id=$_GET['id'];
//$id = (isset($_GET['id']) ? $_GET['id'] : '');
if (isset($_POST['update']))
{
//$arr=implode(",",$hobbies);
$first=$_POST['first'];
//echo $first;
$last=$_POST['last'];
//echo $last;
$email=$_POST['email'];
//echo $email;
$mobile=$_POST['mobile'];
//echo $mobile;
$gender=$_POST['gender'];
//echo $gender;
$hobbies=$_POST['hobbies'];
$arr=implode(",",$hobbies);
//echo $arr;
$message=$_POST['Message'];
$sql = "UPDATE forms SET first_name='$first',last_name='$last',email='$email',mobile='$mobile',gender='$gender',hobbies='$arr',message='$message' WHERE id='".$id."'";
//echo $sql;
//die;
$qeury=mysqli_query($connection,$sql);
if($qeury){
header('location:select.php');
exit;
}
else
{
echo 'not update';
}
}


$select= "SELECT * FROM forms WHERE id='".$id."'";
$result = mysqli_query($connection,$select);
while($row = mysqli_fetch_array($result)){


?>

<form action="" method="post" enctype="multipart/form-data">
<p>First Name:<input type="text" name="first" placeholder="First Name" value= <?php echo $row['first_name'];?>>
Last Name:<input type="text" name="last" placeholder="Last Name" value= <?php echo $row['last_name'];?>></p>
<p>Email:<input type="email" name="email" placeholder="Email" value= <?php echo $row['email'];?>>
Mobile:<input type="tele" name="mobile" placeholder="Mobile" value= <?php echo $row['mobile'];?>></p

<p>
Gender: 
Male<input type="radio" name="gender" value="Male" <?php if($row['gender']=="Male"){echo "checked";}?>/>

Female<input <?php if($row['gender']=="Female"){echo "checked";}?> type="radio" name="gender" value="Female"/>
</p>

<p>Hobbies:
<?php 
$chkbox=$row['hobbies'];
$arr=explode(",",$chkbox);
//print_r($arr);
//die;
?>
Singing <input <?php if(in_array("Singing",$arr)){echo "checked";}?> type="checkbox" name="hobbies[]" value="Singing" />
Dancing <input <?php if(in_array("Dancing",$arr)){echo "checked";}?> type="checkbox" name="hobbies[]" value="Dancing" />
Art <input <?php if(in_array("Art",$arr)){echo "checked";}?> type="checkbox" name="hobbies[]" value="Art" />
cricket <input <?php if(in_array("Cricket",$arr)){echo "checked";}?> type="checkbox" name="hobbies[]" value="Cricket" /><br>
</p>

<p>
<textarea name="Message" rows="5" cols="40" placeholder="Enter Message">
<?php echo $row['message'];?>
</textarea>

<input type="submit" name="update" value="Update" >
</p>
<?php } ?>
</form>


1 comment: