Tuesday, December 24, 2024

Task 4: Create a HTML index page with only one form field with name and submit it in to database age using insert command in Same field without creating another page

Lets create a query for this code in same index.php page using the code given below

 <?php
$conn = mysqli_connect('localhost', 'ksumanadhikari', 'welcome', 'age') or die("Connection failed");
if (isset($_POST['num'])) {
    $num = $_POST['num'];
    $sql = "INSERT INTO age(num) VALUES ('$num')";
    mysqli_query($conn, $sql);
}
mysqli_close($conn);
?>
<html>
<body>

    <form action="index.php" method="post">
        <input type="number" name="num">
        <input type="submit">
    </form>
</body>
</html>

This code will give the output on Mysql when we insert any code inside the box it will add into the database.

 

The Database View

0 comments:

Post a Comment

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