1
My application is the following, words are typed into a form, and the program identifies the amount of characters it has, if that amount is ODD, it adds the word into a table
see how it works, in case the word typed was Jao.
ai if I add another odd word, it creates the table only with the current word.
wanted to know how do I go adding every odd word in the table, without creating a new table just with the current word typed.
follows the code:
<?php
session_start();
$_SESSION['var'] = array();
$_SESSION['tam'] = array();
function postImpar($nome){
if((strlen($nome) % 2)!= 0){
array_push($_SESSION['var'], $nome);
array_push($_SESSION['tam'], strlen($nome));
}
}
echo'<form action="calcula.php" method="post">
<br />Nome:<input type="text" name="nome" /><br /><br />
<input type="submit" />
</form>';
echo "<h1>Ímpares</h1>";
echo'<table border="1">';
if (isset($_POST["nome"])) {
postImpar($_POST["nome"]);
$x = $_SESSION['var'];
$y = $_SESSION['tam'];
$tam = count($x);
for($i = 0; $i < $tam; $i++){
echo "<tr>"."<td>$x[$i]</td>".
"<td>$y[$i]</td>".
"</tr>";
}
}
echo"</table>";
?>
Every time you send a subit is resetting the value of the
$_SESSION
, remove or comment those lines$_SESSION['var'] = array();
 $_SESSION['tam'] = array();
– rray
Vlw, for the help was that, I didn’t know I was resetting Thank you, God pay you.
– Rodrigo Jacinto