mysql查询没有传递所有变量

时间:2017-07-12 16:54:18

标签: php mysql sql

<?php
  require ('navbar.php');
?>

<div class="container">
    <div class="row">
        <div class="well text-center">
            <h1>Sell Ticket</h1>
        </div>          

        <br>
        <br>

<?php 
// Create a login/logout link:
session_start();

// make sure user is logged in
if (!isset($_SESSION['umid'])) {
    header("Location: /sell-ticket-login");
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    require ("mysqli_connect.php");
    $errors = array();
    if (empty($_POST['section'])) {
        $errors[] = 'Your forgot to enter your section';
    } else {
        $sec = mysqli_real_escape_string($dbc, trim($_POST['section']));
    }

    if (empty($_POST['row'])) {
        $errors[] = 'Your forgot to enter your row';
    } else {
        $ro = mysqli_real_escape_string($dbc, trim($_POST['row']));
    }

    if (empty($_POST['seat'])) {
        $errors[] = 'Your forgot to enter your seat';
    } else {
        $sea = mysqli_real_escape_string($dbc, trim($_POST['seat']));
    }

    if (empty($_POST['price'])) {
        $errors[] = 'Your forgot to enter your price';
    } else {
        $pri = mysqli_real_escape_string($dbc, trim($_POST['price']));
    }
}

$g = $_GET['id'];
echo $g;
echo " ".$g;

if (empty($errors)) {

    // dont forget info about name. login
    $q1 = "INSERT INTO tickets 
                    (game_id, section, row, seat, price, date)  
            VALUES ('$g', '$sec', '$ro', '$sea', '$pri', NOW())";

    $r = mysqli_query($dbc, $q1);
    if ($r) {

        echo '<div class="row">
                    <div class="col-lg-4">
                    </div>
                        <div class="well well-sm col-lg-4">
                        <h4 class="text-center">Thank You! Your Ticket has been submitted</h4>
                    </div>
                </div>
                ';
    }

} else {

    echo '<h1>Error!</h1>
        <p class="error">The following error(s) occurred:<br />';
        foreach ($errors as $msg) { // Print each error.
            echo " - $msg<br />\n";
        }
            echo '</p><p>Please try again.</p><p><br /></p>';
}

mysqli_close($dbc);
 ?>

  <h2 class="text-center">Ticket Info</h2>

    <form action="sell-ticket.php" method="post">


        <div class="row">
            <div class="col-lg-4">
            </div>
            <div class="form-group col-lg-4">
                    <label for="text">Section:</label>
                    <input type="text" class="form-control" name="section">
                </div>
            </div>

            <div class="row">
            <div class="col-lg-4">
            </div>
                <div class="form-group col-lg-4">
                    <label for="text">Row:</label>
                    <input type="text" class="form-control" name="row">
                </div>
            </div>

            <div class="row">
            <div class="col-lg-4">
            </div>
                    <div class="form-group col-lg-4">
                    <label for="text">Seat:</label>
                    <input type="text" class="form-control" name="seat">
                </div>
            </div>

            <div class="row">
            <div class="col-lg-4">
            </div>
                <div class="form-group col-lg-4">
                    <label for="text">Price</label>
                    <input type="text" class="form-control" name="price">
                </div>
            </div>

            <div class="row">
            <div class="col-lg-4">
            </div>
                <div class="col-lg-4">
                    <button type="submit" class="btn btn-default">Submit</button>
            </div>
        </div>
    </form>
  <footer>
  <p>&copy; 2017 MichMarket, Inc.</p>
 </footer>

 </div>
 <!--/.container-->
 </body>

 </html>

由于某种原因,我的查询有效,但唯一没有传递到我的数据库的值是$ g。我将$ g的值用于测试目的,并显示在我的网页上。所有其他值都正确地传递到我的数据库中。我从html中收到所有其他值,我通过$ _GET收到$ g。

在我的查询中,当我将$ g更改为特定值时,它将传递到我的数据库中。关于为什么这不起作用的任何想法为什么我想要它?

1 个答案:

答案 0 :(得分:0)

找出问题所在。在我的表单中,我将它链接到一个不同的URL而没有$ id有一个值,所以$ g在我提交查询时没有值。