Wednesday, December 25, 2024

Task 5: Create a website with one index page with one entry field and submit button and enter some number on it using form and display it below using a table.

 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>
</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("Connection error");
$num=$_POST['num'];
$sql="insert into data(num) values('$num')";
mysqli_query($conn,$sql);
header("location: index.php");
exit();
?>

Database View 

webview

0 comments:

Post a Comment

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