1
I’m trying to create a simple function, to write the title according to the gender selection on the form, but I must be doing something wrong:
$sexo = empty($_POST['sexo']) ? "[sexo]" : $_POST['sexo'];
function mudasexo($sexo) {
if ($sexo == "masculino") {
echo "O senhor";
}
else {
echo "A senhora";
}
}
Hence I wanted to use this function within HTML texts with: <?php mudasexo() ?>
but it is not working. It does not accuse any error when threshing, but the page doesn’t even open.
In my test appeared "The Lady"
– user6406
The problem seems not to be the function, if call her as it is there works.
– rray
@rray Can it be because this file where I put the function is included via include in one file, which is then included in another? Now looking right at the debug here I found this PHP error
Fatal error: Cannot redeclare mudasexo() (previously declared in arq1.php:90) in arq1.php on line 98
...– gustavox
Just delete the version of the function that is in the wrong place.
– rray
This @rray! @gustavox, enable error Reporting
– user6406
No, the function is declared only once. It’s like this, when the form runs it calls a file (saida.php, which is html/php), and at the end of this file has a include that calls another file (saida2php - which tbm is an html/php file), and this one that calls just another script (and this is where the function is, and this script only acts on the output 2php file). @rray
– gustavox
Then the output file.php (the first) opens only half, when it starts the 2 no longer opens... Only remove the function...
– gustavox
I thought it had to do with when the if/Else, but I think it has to do with the way using include and such... thanks anyway to all who helped... Hugs.
– gustavox
you call for include or include_once ?
– rray
Ah @rray, by include (but I changed to include_once now hehe), but when I read your comment I went to look and I was calling the script file on both pages (left and left 2)... calling only on the first worked! thanks^^
– gustavox