if(isset($ _ POST [“ btnSubmit”]))无法正常工作。我的按钮是可单击的,但似乎没有执行我需要它执行的查询。
这很奇怪,因为我在同一个webapp的另一个脚本中有一段非常相似的代码,但是可以正常工作,但是这根本行不通。
<?php
$query = "SELECT * FROM MOVIES";
$result = mysqli_query($con,$query);
if(isset($_POST["btnSubmit"])){
$quantity = $_POST["quantity"];
$movie = $_POST["movie"];
$sql= sprintf("UPDATE MOVIES SET tickets = (tickets - %d) WHERE title = %s",$quantity,$movie);
if(!mysqli_query($con,$sql)){
die('Error:'.mysqli_error($con));
}
echo "<h2>You ordered ".$quantity." ".$movie."tickets</h2>";
}
?>
<body>
<div class="jumbotron">
<div class ="form-group" method="post">
<label for="sel1"><h3>Pick a movie:</h3></label>
<select class="form-control" id="sel1" name="movie">
<?php while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
print "<option value='".$title."'>".$row[title]."</option>";
}
?>
</select>
<div class="form-group">
<label for="q"><h3>Quantity:</h3></label>
<input name="quantity" type="text" class = "form-control" id="quantity" placeholder="Please enter quantity"/>
</div>
<div class="form-group" method="post" action="">
<label for="btnSubmit">ORDER!</label>
<input type="submit" name="btnSubmit" id= "btnSubmit" class="form-control btn btn-success">
</div>
</div>
</body>
我希望它通过减去数据库中的票证数量来单击并更新表,但是该按钮不会执行任何操作。