I am trying to use a single .php page to have a conditional MySQLi INSERT based on user role. Basically, the INSERT is very similar with the exception of a couple of fields. Here is my code:
require 'scripts/config.php';
if ($_SESSION['role'] == 'admin')
{
SQL Option 1 INSERT/PREPARE/BIND/EXECUTE .....
}
if ($_SESSION['role'] == 'client')
{
SQL Option 2 INSERT/PREPARE/BIND/EXECUTE .....
}
What happens is that regardless of the user $_SESSION, both INSERT statements execute. One entry is blank and the other has the correct data based on the form submitted.
My form is the same with the exception of a couple of conditional fields that are different based on admin vs client.
Can I do this or do I need to go back to the original script that has two different .php pages that contains the INSERT statement for admin vs client like this:
if ($_SESSION['role'] == 'admin')
{
header("Location: admin.php")
}
if ($_SESSION['role'] == 'client')
{
header("Location: client.php")
}
Aucun commentaire:
Enregistrer un commentaire