0

How can you send this kind of form to database with something like this +----+-------+-------+-------+--------+
| id | dcode | lname | fname | mname  |
+----+-------+-------+-------+--------+
|  1 |  3242 | Doe   | John  | Miller |
|  2 |  3242 | Smith | Peter | Brown  |
|  3 |  2412 | Wood  | Kian  | Taylor |
|  4 |  1534 | Burns | Dylan | Butler |
+----+-------+-------+-------+--------+

You registered your classmates John Doe and Peter Smith in one submission that is why they have the same dcode. While the rest is separate

$('#add-btn').click(function(){

        const elem = '    <input type="text" name="dcode" hidden value="<?php echo(mt_rand(100000000,999999999)); ?>"><input class="form-control" type="text" name="lname[]" placeholder="Last Name" required><input class="form-control" type="text" name="fname[]" placeholder="First Name" required><input class="form-control" type="text" name="mname[]" placeholder="Middle Name" required><br>';

        $('#add-btn').before(elem);

    })
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" rel="stylesheet">
</head>
<body>
    <form method="POST" action="classmate_insert.php">
        <div class="form-group col-6 mx-auto m-5">
            <label for="dependents">Classmates:</label>

            <button id="add-btn" class="form-control btn-danger">Add</button><br>
            <button type="submit" class="btn btn-primary float-right ">Submit</button>
        </div>
    </form>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js"></script>

</body>
<script type="text/javascript">

</script>
</html>
  • take a look at this https://stackoverflow.com/questions/9073690/post-an-array-from-an-html-form-without-javascript – nbk Nov 30 '20 at 18:26
  • do you think what i did is possible to insert in database? –  Nov 30 '20 at 22:54
  • yes you can do this with the all that is mentioned in the link, especial the array part is vital for the html and php part. The link shows everything you need to know, copoy the code play around with it and then adapt your cpde. – nbk Nov 30 '20 at 22:56

0 Answers0