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