Add Data

 <?php include 'header.php'; ?>

<div id="main-content">
    <h2>Add New Record</h2>
    <form class="post-form" action="savedata.php" method="post">
        <div class="form-group">
            <label>Name</label>
            <input type="text" name="sname" />
        </div>
        <div class="form-group">
            <label>Address</label>
            <input type="text" name="saddress" />
        </div>
        <div class="form-group">
            <label>Class</label>
            <select name="class">
                <option value="" selected disabled>Select Class</option>
                <?php
                $conn = new mysqli("localhost", "root", "", "crud");
                if ($conn->connect_error) {
                    die("Connection Failed : " . $conn->connect_error);
                }

                $sql = "SELECT * FROM studentclass";
                $result = $conn->query($sql);

                if ($result->num_rows > 0) {
                    while ($row = $result->fetch_assoc()) {

                ?>
                        <option value="<?php echo $row["cid"]; ?>"><?php echo $row["cname"]; ?></option>
                <?php
                    }
                } else {
                    echo "No Record Found";
                }
                $conn->close();
                ?>
            </select>
        </div>
        <div class="form-group">
            <label>Phone</label>
            <input type="text" name="sphone" />
        </div>
        <input class="submit" type="submit" value="Save" />
    </form>
</div>
</div>
</body>

</html>

Comments

Popular posts from this blog

Update Record File in PHP

Index File in PHP

Edit OR Update Data File in PHP