是否有可能有$ _SESSION = $ _POST? [英] Is it possible to have $_SESSION = $_POST?

查看:124
本文介绍了是否有可能有$ _SESSION = $ _POST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我是否做错了,但我们可以说我有这个。

I don't know if I'm doing wrong but let's say I have this.

formulario.php

<? session_start(); 
   $_SESSION['promedio'] = $number; 
   echo '
   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
   <html>

   <meta content="text/html; charset=utf-8" http-equiv=Content-Type>
   <body>
   <form action="main3.php" method="post">

   Número de Encuestas <input type="number" name="number">
  <input type="submit" value="Enviar"/>

   </form>
   </body>
   </html> ';

   ?>

现在,在 main3.php 中加入

Now, in main3.php

<?
  session_start();

  $number = $_POST['number'];
  $_SESSION['promedio'] = $number;


  function Calcular($edades, $estado_civil, $genero){
  global $number;
foreach($edades as $edad){} 
echo "El promedio de edad general es: ".((array_sum($edades))/$number)."<br>";


$x; 
$y; 
$z; 
$w; 
$v;
$u;
$t;
foreach ($genero as $i) {
    foreach ($i as $j) {
        if($j == "Hombres")
        {
            $u++;
        }
        if($j == "Mujeres")
        {
            $t++;
        }
        $count_values[$j]++;
    }
}
echo "Cantidad de hombres: ".$u."<br>",
     "Cantidad de mujeres: ".$t."<br>"; 
foreach ($estado_civil as $a) {
    foreach ($a as $b) {
        if($b == "Soltero")
        {
            $x++;;
        }
        if($b == "Casado")
        {
            $y++;
        }
        if($b == "Separado")
        {
            $z++;
        }
        if($b == "Libre")
        {
            $w++;
        }
        if($b == "Viudo")
        {
            $v++;
        }
        $count_values[$b]++;
    }
}
echo "Cantidad de personas solteras: ".$x."<br>", 
     "Cantidad de personas casadas: ".$y."<br>",
     "Cantidad de personas separadas: ".$z."<br>",
     "Cantidad de personas en unión libre: ".$w."<br>",
     "Cantidad de personas viudas: ".$v."<br>";

  }

  echo '<form type="submit" action="resultados.php" method="post">';
  for ($i=0; $i < $number; $i++) { 

  echo '
  <html>
  <h2>Datos de la persona '.$i.'</h2> 
  Edad <input type="number" name="edades[]"/> <br><br>
  Sexo <br><br>
  <input type="radio" name="genero['.$i.'][]" value="Hombres"/> Masculino <br>
  <input type="radio" name="genero['.$i.'][]" value="Mujeres"/> Femenino <br><br>
  Estado Civil <br><br>
  <input type="radio" name="estado_civil['.$i.'][]" value="Soltero"/> Soltero <br>
  <input type="radio" name="estado_civil['.$i.'][]" value="Casado"/> Casado <br>
  <input type="radio" name="estado_civil['.$i.'][]" value="Separado"/> Separado <br>
  <input type="radio" name="estado_civil['.$i.'][]" value="Libre"/> Unión Libre <br>
  <input type="radio" name="estado_civil['.$i.'][]" value="Viudo"/> Viudo <br><br> ';
  }

  echo '
  <input type="submit">
  </form>
  </html> ';

  ?>

最后一个文件 resultados.php

<?
include ("main3.php");
echo Calcular($_POST['edades'], $_POST['estado_civil'], $_POST['genero']);

?>

因此,如您所见,我将 $ number 变量称为一个功能,这是问题所在。当我在 Average()中调用它时,它一直说我被零除,这意味着 $ number 不会通过 $ _ SESSION STRONG>。我有一些事情可以让这个工作,但没有运气。

So, as you can see, I call the $number variable into a function and this is where the problem is. It keeps saying I'm dividing by zero, which means $number isn't saving the value through $_SESSION when I call it in Average(). I've some things to get this to work, but no luck.

任何建议或帮助我失踪的东西将不胜感激。

Any suggestion or help about what I'm missing would be appreciated.

推荐答案

问题是,当您将 main3.php 中的表单提交到 resultados.php ,没有数字输入。您可以将其添加为第二种形式的隐藏输入:

The problem is that when you submit the form in main3.php to resultados.php, there's no number input. You can add it as a hidden input in the second form:

echo '<form type="submit" action="resultados.php" method="post">';
echo "<input type='hidden' name='number' value='$number'>";

另外,您不应输出< html> main3.php for 循环中的$ c>。

Also, you shouldn't output <html> in the for loop in main3.php.

这篇关于是否有可能有$ _SESSION = $ _POST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆