通过PHP中的提交输入显示数组值

时间:2014-10-03 04:42:11

标签: php html mysql

我在通过提交输入时显示数组值时出现问题。

我对PHP编码很新,我想知道如何将复选框中的值转换为提交输入,最后:显示到网页。

**编辑 - 我已更新并包含了我正在处理的整个页面。澄清使用这两个数组的任何混淆。

<?php
//if ($_COOKIE["auth"] == "1") {
  if (filter_input (INPUT_COOKIE, 'auth') == "1") {
    $display_block = "<p>You are an authorized user.</p>";
} else {
    //redirect back to login form if not authorized
    header("Location: userlogin.html");
    exit;
}

$num = range(1,49);//Create a range of numbers from 1-49.

shuffle($num); //Shuffle the numbers
$lotto=array_slice($num,0,6); //Grab 6 random numbers from $num

shuffle($num); //Shuffle & generate 49 numbers.
$lottoMax=array_slice($num,0,7); //Grab 7 random numbers from $num

sort($lotto);
sort($lottoMax);

?>
<html>
<head>
    <title>Lottery Tickets</title>
</head>
<body>
    <form action="" name="Lottery Tickets" method="post">
        <input type="checkbox" name="lotto[]" value="lotto"> Lotto 6/49
        <input type="checkbox" name="lottoMax[]" value="lottoMax"> Lotto MAX
        <input type="submit" name="submit">
    </form>
    <p>
        <?php
            if(isset($_POST['submit'])){
                $lotto=$_POST['lotto'];
                    foreach($lotto as $name){
                        echo $name.'<br/>';
                    }
            }
            if(isset($_POST['submit'])){
                $lottoMax=$_POST['lottoMax'];
                    foreach($lotto as $name){
                        echo $name.'<br/>';
                    }
            }
        ?>
    </p>
</body>

任何建议/提示/帮助将不胜感激!谢谢。

1 个答案:

答案 0 :(得分:0)

<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$num = range(1,49);//Create a range of numbers from 1-49.

shuffle($num); //Shuffle the numbers
$lotto=array_slice($num,0,6); //Grab 6 random numbers from $num

shuffle($num); //Shuffle & generate 49 numbers.
$lottoMax=array_slice($num,0,7); //Grab 7 random numbers from $num

sort($lotto);
sort($lottoMax);

?>
<html>
<head>
    <title>Lottery Tickets</title>
</head>
<body>
    <form action="" name="Lottery Tickets" method="post">
        <input type="checkbox" name="lotto" value=""> Lotto 6/49
        <input type="checkbox" name="lottoMax" value=""> Lotto MAX
        <input type="submit" name="submit">
    </form>
    <p>
        <?php

            if(isset($_POST['submit']) ){
              $lottorey1=$_POST['lotto'];
              $lotterey2=$_POST['lottoMax'];

            if(isset($lottorey1)==TRUE)
            {
                $num = range(1,49);//Create a range of numbers from 1-49.

shuffle($num); //Shuffle the numbers
$lotto=array_slice($num,0,6); //Grab 6 random numbers from $num

echo 'Lotto 6/49: ';
foreach ($lotto as $lotto_num)
{
    echo $lotto_num.' ';
}
            }
            echo '<br/>';  
            }
        ?>
    </p>
</body>