在PHP中保存数据的最佳方法是什么

时间:2014-04-28 16:35:26

标签: php html

我正在开展一个用户可以进行多次投票的项目。我的问题是如何在PHP中保存一页数据。这是我试图保存的数据页面。

<?php session_start();

    $user = $_SESSION['user'];
    $cod = $_SESSION['cod'];

    $race1=  $_SESSION['race_one'];
    $race2 =  $_SESSION['race_two'];
    $race3 =  $_SESSION['race_three'];

    $_SESSION['person11'] = $_POST['person11'];
    $_SESSION['party11'] = $_POST['party11'];
    $_SESSION['person21'] = $_POST['person21'];
    $_SESSION['party21'] = $_POST['party21'];
    $_SESSION['person31'] = $_POST['person31'];
    $_SESSION['party31'] = $_POST['party31'];
    $_SESSION['person12'] = $_POST['person12'];
    $_SESSION['party12'] = $_POST['party12'];
    $_SESSION['person22'] = $_POST['person22'];
    $_SESSION['party22'] = $_POST['party22'];
    $_SESSION['person32'] = $_POST['person32'];
    $_SESSION['party32'] = $_POST['party32'];
    $_SESSION['person13'] = $_POST['person13'];
    $_SESSION['party13'] = $_POST['party13'];
    $_SESSION['person23'] = $_POST['person23'];
    $_SESSION['party23'] = $_POST['party23'];
    $_SESSION['person33'] = $_POST['person33'];
    $_SESSION['party33'] = $_POST['party33'];

    $pr1_1 = $_SESSION['person11'];
    $py1_1 = $_SESSION['party11'];
    $pr2_1 = $_SESSION['person21'];
    $py2_1 = $_SESSION['party21'];
    $pr3_1 = $_SESSION['person31'];
    $py3_1 = $_SESSION['party31'];
    $pr1_2 = $_SESSION['person12'];
    $py1_2 = $_SESSION['party12'];
    $pr2_2 = $_SESSION['person22'];
    $py2_2 = $_SESSION['party22'];
    $pr3_2 = $_SESSION['person32'];
    $py3_2 = $_SESSION['party32'];
    $pr1_3 = $_SESSION['person13'];
    $py1_3 = $_SESSION['party13'];
    $pr2_3 = $_SESSION['person23'];
    $py2_3 = $_SESSION['party23'];
    $pr3_3 = $_SESSION['person33'];
    $py3_3 = $_SESSION['party33'];

    if($cod == 1 ){

?>
<html>
<head>
        <title>Ballot Pro | Ballot Preview</title>
</head>
<body>
    <p><center>Current user, <? echo $user; ?>.</center></p>

    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"><center>

        <label><? echo $race1; ?></label><br />
            <input type ="radio" name="pick" value="$pr1_1" ><? echo $pr1_1 . " for the party " . $py1_1; ?><br />
            <input type ="radio" name="pick" value="$pr2_1" ><? echo $pr2_1 . " for the party " . $py2_1; ?><br />
            <input type ="radio" name="pick" value="$pr3_1" ><? echo $pr3_1 . " for the party " . $py3_1; ?><br /><br />

        <input type="submit" value="Submit" /></center>
    </form>
</body>
</html>
<?
    }
    else if($cod == 2){
?>
<html>
<head>
        <title>Ballot Pro | Ballot Preview</title>
</head>
<body>
    <p><center>Current user, <? echo $user; ?>.</center></p>

    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"><center>

        <label><? echo $race1; ?></label><br />
            <input type ="radio" name="pick" value="$pr1_1" ><? echo $pr1_1 . " for the party " . $py1_1; ?><br />
            <input type ="radio" name="pick" value="$pr2_1" ><? echo $pr2_1 . " for the party " . $py2_1; ?><br />
            <input type ="radio" name="pick" value="$pr3_1" ><? echo $pr3_1 . " for the party " . $py3_1; ?><br /><br />

        <label><? echo $race2; ?></label><br />
            <input type ="radio" name="pick" value="$pr1_2" ><? echo $pr1_2 . " for the party " . $py1_2; ?><br />
            <input type ="radio" name="pick" value="$pr2_2" ><? echo $pr2_2 . " for the party " . $py2_2; ?><br />
            <input type ="radio" name="pick" value="$pr3_2" ><? echo $pr3_2 . " for the party " . $py3_2; ?><br /><br />

        <input type="submit" value="Submit" /></center>
    </form>
</body>
</html>
<?
    }
    else if($cod == 3){
?>
<html>
<head>
        <title>Ballot Pro | Ballot Preview</title>
</head>
<body>
    <p><center>Current user, <? echo $user; ?>.</center></p>

    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"><center>

        <label><? echo $race1; ?></label><br />
            <input type ="radio" name="pick" value="$pr1_1" ><? echo $pr1_1 . " for the party " . $py1_1; ?><br />
            <input type ="radio" name="pick" value="$pr2_1" ><? echo $pr2_1 . " for the party " . $py2_1; ?><br />
            <input type ="radio" name="pick" value="$pr3_1" ><? echo $pr3_1 . " for the party " . $py3_1; ?><br /><br />

        <label><? echo $race2; ?></label><br />
            <input type ="radio" name="pick" value="$pr1_2" ><? echo $pr1_2 . " for the party " . $py1_2; ?><br />
            <input type ="radio" name="pick" value="$pr2_2" ><? echo $pr2_2 . " for the party " . $py2_2; ?><br />
            <input type ="radio" name="pick" value="$pr3_2" ><? echo $pr3_2 . " for the party " . $py3_2; ?><br /><br />

        <label><? echo $race3; ?></label><br />
            <input type ="radio" name="pick" value="$pr1_3" ><? echo $pr1_3 . " for the party " . $py1_3; ?><br />
            <input type ="radio" name="pick" value="$pr2_3" ><? echo $pr2_3 . " for the party " . $py2_3; ?><br />
            <input type ="radio" name="pick" value="$pr3_3" ><? echo $pr3_3 . " for the party " . $py3_3; ?><br /><br />

        <input type="submit" value="Submit" /></center>
    </form>
</body>
</html>
<?}?>

我正在考虑将数据保存在并行数组中并且这样可行,但是有没有其他方法可以让你们建议这样做。

0 个答案:

没有答案