Hello everyone,
I am new to php and I need a confirmation if this is the correct approach for a code I wrote. Basically, I have a contacts.php page where I have a bootstrap table and a modal with some fields to add a new contact. I managed to write all the code, it works perfect but I want to know if this approach is ok. The application will be much more complex and I don;t want to start on the wrong foot here. I have 2 files: contacts.php and add_new_contact.php.
First file, contacts.php:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<!-- ............ -->
</head>
<body>
<!-- ............ here is the page layout-->
<!-- Then I have my modal from bootstrap -->
<div class="modal fade" id="addContact" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<form action = "add_new_contact.php" method="post">
<!-- .....content with all the inputs -->
<button type="submit" class="btn btn-primary">Save to database</button>
</form>
</div>
</body>
</html>
Now, in form action I am telling html to go to add_new_contact.php where I wrote the code for inserting all the values to the database. When doing this, it opens the page and it stays blank because there is no html there. So, in that php file I added a redirect code to the initial contacts.php. Here is the code:
Second file: add_new_contact.php:
<?php
//all the code needed to insert the contact in the database
header("Location: http//..../contacts.php");
exit();
?>
So, this works fine. But is this the best way to do it?
Thank you.