-1

I have 2 php files:

index.php

<?php
@ini_set('default_charset', 'ISO-8859-1');
echo '<form method=post action="aplicacao.php">';
echo '<input type="hidden" name="username" value="Joaquim"/>';
echo '<input type="hidden" name="permissoes" value="administrador"/>';
echo '<input style="margin-left: 1150px; cursor=pointer;" type="submit" name="autorizado" value="Aplicação - Administração"></form>';
echo '<hr>';
echo '<form method=post action="aplicacao.php">';
echo '<input type="hidden" name="username" value="Joaquim"/>';
echo '<input type="hidden" name="permissoes" value="vendedor"/>';
echo '<input style="margin-left: 1150px; cursor=pointer;" type="submit" name="autorizado" value="Aplicação - Vendedor"></form>';
?>

aplicacao.php

<?php
if(isset($_POST['autorizado']))
{
    if($_POST['permissoes'] == 'administrador')
    {
        //something here
    }
    if($_POST['permissoes'] == 'vendedor')
    {
        //and something here
    }
}
?>

Then, when I submit POST, aplicacao.php turns white.

I know why, but I don't know how to solve.

Some help would be appreciated.

Greetings!

Shaunak Shukla
  • 2,347
  • 2
  • 18
  • 29

2 Answers2

0

If you want to return to your index.php page, use the php header function to redirect:

    <?php
if(isset($_POST['autorizado']))
{
    if($_POST['permissoes'] == 'administrador')
    {
        //something here
    }
    if($_POST['permissoes'] == 'vendedor')
    {
        //and something here
    }
}

header('Location: index.php');
?>
N.P.
  • 181
  • 2
  • 12
  • I want to stay at aplicacao.php after POST – Henrique Soares Jul 06 '17 at 09:08
  • You can add content to the aplicacao.php page (like you did on index.php, use echo). – N.P. Jul 06 '17 at 09:12
  • I have content: inputs text and submit button – Henrique Soares Jul 06 '17 at 09:24
  • Ow, so you want your index.php in your aplicacao.php page? You can use 'include' for this. Put `include 'index.php';` instead of the header function – N.P. Jul 06 '17 at 09:30
  • I don't wanna go to index.php. I wan't to stay at aplicacao.php after POST – Henrique Soares Jul 06 '17 at 10:06
  • That's what include does... It includes your index.php file in aplicacao.php. [read more here](http://php.net/manual/en/function.include.php) – N.P. Jul 06 '17 at 10:44
  • I don't want to include index.php in aplicacao.php. – Henrique Soares Jul 06 '17 at 11:08
  • You want informationfrom index.php but you don't want to include it? You can copy the echo statements ... [or set the form action to "" and handle the POST-request on the index page (or include the aplicacao.php in your index page).](https://stackoverflow.com/questions/17333901/php-form-on-submit-stay-on-same-page) . Or send the form using Ajax... – N.P. Jul 06 '17 at 12:18
-1

What do you expect to see on the aplicacao.php page? If you want to see the same form, you need to create routing and .htaccess with something like this

RewriteEngine on
RewriteRule !\.(js|gif|phg|jpg|css)$ index.php