Wednesday, December 25, 2024

Task 6: You have to Edit your Task 5 data using another page named 'edit.php' and you need to make Fetch your changing number will appear on it .

index.php

 <html>
<body>
<?php
$conn=mysqli_connect('localhost','ksumanadhikari','welcome','task');
$sql='select * from data';
$result=mysqli_query($conn,$sql);
?>

<form action="submit.php" method="post">
    <input type="number" name="num">
    <button name="submit">Submit</button>
</form>
<?php
if(mysqli_num_rows($result)>0){
?>
<table border="1">
<tr>
<th>sn</th>
<th>num</th>
</tr>
<?php
while($row=mysqli_fetch_assoc($result)) {
?>
<tr>
<td><?php echo $row['sn'];?></td>
<td><?php echo $row['num'];?></td>
<td><a href='edit.php?sn=<?php echo $row['sn'];?>'>Edit</a></td>
<td><a href='delete.php?sn=<?php echo $row['sn'];?>'>delete</a></td>
</tr>


<?php } ?>
</table>
<?php }else {
    echo "no table found";
    mysqli_close($conn);
    } ?>
</body>
</html>

 

submit.php

<?php
$conn=mysqli_connect('localhost','ksumanadhikari','welcome','task') or die("margaya madarchood! la la lalalalalalala la la");
$num=$_POST['num'];
$sql="insert into data(num) values('$num')";
mysqli_query($conn,$sql);
header("location: index.php");
exit();
?>



edit.php

<?php
$conn=mysqli_connect('localhost','ksumanadhikari','welcome','task') or die("connection failed");
$sn=$_GET['sn'];
$sql="select * from data where sn='$sn'";
$result=mysqli_query($conn,$sql);

if(mysqli_num_rows($result)>0){
    while($row=mysqli_fetch_assoc($result)) {
?>
<form action="update.php" method="post">
SN <input type="number" name="sn" value="<?php echo $row['sn']; ?>" />
Change Number <input type="number" name="num" value="<?php echo $row['num']; ?>" />
<input type="submit" value="Update Data">
</form>
<?php } } ?>

0 comments:

Post a Comment

Copyright © Web Devloper LogBook | Powered By Blogger | Blogger Templates
Design by Saeed Salam | Blogger Theme by NewBloggerThemes.com