For循环仅显示最终结果

时间:2018-07-18 08:31:58

标签: php html postgresql

我有以下PHP查询:

    <?php
    $row='';
    $access = 0;
    $user = (isset($_POST['nume']) && !empty($_POST['nume'])) ? $_POST['nume'] : "" ;
    $email = (isset($_POST['email']) && !empty($_POST['email'])) ? $_POST['email'] : "" ;
    $telefon = (isset($_POST['telefon']) && !empty($_POST['telefon'])) ? $_POST['telefon'] : "" ;
    $cnp = (isset($_POST['cnp']) && !empty($_POST['cnp'])) ? $_POST['cnp'] : "" ;
    $serieci = (isset($_POST['serieci']) && !empty($_POST['serieci'])) ? $_POST['serieci'] : "" ;
    $mesaj = (isset($_POST['mesaj']) && !empty($_POST['mesaj'])) ? $_POST['mesaj'] : "" ;
    $email_status=1;

    $db = pg_connect("host=local port=5432 dbname=login_robinson user=robinson password=123");
    $query = "INSERT INTO tcheckin(nume,email,telefon,cnp,serieci,mesaj) VALUES ('$user','$email','$telefon','$cnp','$serieci','$mesaj')";
    $result = pg_query($query);
    $test=$_SESSION[PRE.'nume'];
    $test1=$_SESSION[PRE.'uid'];
?>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

    <head>
        <link href="https://fonts.googleapis.com/css?family=Playfair+Display:400,700,900|Rubik:300,400,700" rel="stylesheet">


        <title>Efectueaza check-in</title>
        <?php
            include('include/links.php');
            include('include/scripts.php');
        ?>

    </head>
    <?php
    $i=1;
    $conn = pg_connect("host=local port=5432 dbname=login_robinson user=robinson password=123");
    $test1=$_SESSION[PRE.'uid'];
    $result = pg_query($conn, "SELECT nume FROM tregister WHERE id = '$test1'");
    if (!$result) {
        echo "An error occurred.\n";
        exit;
    }
    $row = pg_fetch_row($result);

    $result1 = pg_query($conn, "SELECT nr_camere FROM tregister WHERE nume = '$user'");
    if (!$result1) {
        echo "An error occurred.\n";
        exit;
    }

    $camere = pg_fetch_row($result1);
    echo $row[0];

    for($i=1; $i<$camere[0]; $i++){
        if(isset($_POST['submit'])){

                echo "<script>
         alert('Check-in efectuat cu success! Daca ai rezervat mai multe camere te rog sa completezi si check-in-ul pentru celelalte camere.');
         window.location.href='acasa';
         </script>";
                echo "<script>
         alert('S-a produs o eroare! Te rog mai verifica odata formularul!');
         </script>";
    }

}

    ?>
    <body style="display: block !important;" ng-cloak="" ng-class="{ 'layout-fixed' : app.layout.isFixed, 'layout-boxed' : app.layout.isBoxed, 'layout-dock' : app.layout.isDocked, 'layout-material': app.layout.isMaterial, 'aside-offscreen' : app.sidebar.isOffscreen, 'aside-mini' : app.sidebar.isMini, 'aside-right' : app.sidebar.isRight, 'footer-hidden': app.footer.hidden, 'in-app': !$state.includes('page')}">

        <div class="animated fadeOutZoom">
            <div class="container container-sm animated fadeInDown">
                <div class="app-view-header">Bine ai venit, <?php echo $row[0]; ?>!</div>
                <div class="center-block mt-xl">

                    <div class="panel">
                        <div class="panel-body">
                            <p class="pv text-bold">Check-in pentru camera cu numarul <?php echo $i; ?></p>
                            <form action="#" method="post">
                                <div class="row">
                                    <div class="col-md-12 form-group">
                                        <label for="nume">Nume</label>
                                        <input type="text" id="text " value=" <?php echo $row[0]; ?>" class="form-control " name="nume" disabled="disabled">
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12 form-group">
                                        <label for="telefon">Telefon</label>
                                        <input type="phone" id="telefon " class="form-control " name="telefon" required>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12 form-group">
                                        <label for="email">Email</label>
                                        <input type="email" id="email" class="form-control " name="email" required>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12 form-group">
                                        <label for="cnp">CNP</label>
                                        <input type="text" id="text " class="form-control "name="cnp" required>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12 form-group">
                                        <label for="serie">Serie de buletin</label>
                                        <input type="text" id="text " class="form-control " name="serieci" required>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12 form-group">
                                        <label for="message">Scrie un mesaj *Optional</label>
                                        <textarea name="mesaj" id="message" class="form-control " cols="5" rows="4"></textarea>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6 form-group">
                                        <input type="submit" value="Rezerva acum" class="btn btn-primary" name="submit">
                                    </div>
                                </div>
                            </form>
                        </div>

                    </div>
                </div>
            </div>
        </div>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js"></script>

        <script>

        $('#arrival_date, #departure_date').datepicker({format: 'dd/mm/yyyy'});


        </script>


    </body>

    </html>
<?php
ob_end_flush();
?>

我想要做的是多次浏览页面。例如,如果用户选择了4个房间,则我需要进行4次签入过程,每个房间一次,我尝试使用for循环,但是它仅显示最终结果。我该怎么办?有点奇怪,我尝试了一段时间,但仍然无法正常工作。

0 个答案:

没有答案