sjthetechguy Posted March 27, 2023 Share Posted March 27, 2023 (edited) Hi, I have this code written, when I input and submit the form, it doesnt post on the databse. Please note that the functions.php file already includes the database connection <?php include("./functions.php"); include("../includes/header_internal.php"); include("../includes/sidebar_internal.php"); ?> <div class="page-body"> <br><br> <div class="card"> <div class="card-header"> <h5>Add Office</h5> </div> <form class="form theme-form"> <form method="post" action="offices.php"> <div class="card-body"> <div class="row"> <div class="col"> <div class="mb-3 row"> <label class="col-sm-3 col-form-label">Office Name</label> <div class="col-sm-9"> <input class="form-control" type="text" name="officeinput"> </div> </div> <div class="card-footer text-end"> <div class="col-sm-9 offset-sm-3"> <button class="btn btn-primary" type="submit">Add Office</button> <input class="btn btn-light" type="reset" value="Cancel"> </div> </div> </form> </div> </div> <?php if (isset($_POST['submit'])) { include("../externalconnectors/database_variables/database_and_databse_tables.php"); $nameoffice = $_POST["officeunput"]; // Insert the data into the database $queryoffice = "INSERT INTO firmoffices (offices) VALUES ('$nameoffice')"; mysqli_query($conn, $queryoffice); } ?> <?php include("../includes/scripts.php"); include("../includes/footer_internal.php"); ?> Edited March 27, 2023 by sjthetechguy Quote Link to comment Share on other sites More sharing options...
Solution kicken Posted March 27, 2023 Solution Share Posted March 27, 2023 12 minutes ago, sjthetechguy said: <form class="form theme-form"> <form method="post" action="offices.php"> You cannot nest forms. That should just be a single form tag with all the attributes, not separate. 13 minutes ago, sjthetechguy said: if (isset($_POST['submit'])) { This will only be true if you have an input in your form with name="submit". Since you do not, it will never be true. A generic test for a form post is to test the request method. if ($_SERVER['REQUEST_METHOD']==='POST'){ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.