Firefog Firefog - 5 months ago 12
MySQL Question

How to run all of my php if function

Why my all if function not run. Only first one run and other not. If I submit my form with the value

A1, A2, A3
it not save all the value at a time but it save the first one. If I submit it individually then works fine.

HTML FORM

<form method="post" action="booking.php" class="form-horizontal ticket-form pull-right" role="form">

<div class="form-group">
<label for="ticket_no" class="col-lg-3 control-label">Your Seat: </label>
<div class="col-lg-8">
<?php
$bus_name = $_GET['bus_name'];
$date = $_GET['date'];
$time = $_GET['time'];

?>
<input class="form-control selected-ticket" id="ticket_no" name="ticket_no" value=""type="text" readonly="readonly" >
<input class="form-control" id="ticket_id" name="ticket_id" value="<?php echo $ticket_id ;?>" type="hidden" >
<input class="form-control" id="user_id" name="username" value="<?php echo $username;?>" type="hidden" >
<input class="form-control" id="bus" name="bus_name" value="<?php echo $bus;?>" type="hidden" >
<input class="form-control" id="date" name="date" value="<?php echo $date;?>" type="hidden" >
<input class="form-control" id="time" name="time" value="<?php echo $time;?>" type="hidden" >

</div>
</div>
<div class="form-group seats-container">
<input name="A1" type="hidden" class="form-control" id="seatvalue" value="A1">
<input name="A2" type="hidden" class="form-control" id="seatvalue" value="A2">
<input name="A3" type="hidden" class="form-control" id="seatvalue" value="A3">
</div>
<!--Your input field willbe visible here-->
</div>


<p>Seat No: <span class="ticket-count" id="ticket-count" > </span></p>

<div class="form-group">
<label for="discount" class="col-lg-4 control-label view-discount">Discount: </label>
<div class="col-lg-8">
<input class="form-control" id="discountdis" placeholder="Click on Discount" disabled>
<input class="form-control discount hide" id="discount" name="discount" type="text" onkeyup="CalcDiscount();" autocomplete="off" max="4">
</div>
<label for="total-price" class="col-lg-4 control-label">Total Price: </label>
<div class="col-lg-8">
<input class="form-control total-price" id="total-price" name="totalprice" type="text" readonly="readonly">
</div>
<label for="customername" class="col-lg-4 control-label"> Customer Name: </label>
<div class="col-lg-8">
<input class="form-control" id="customername" name="customername" type="text" >
</div>
<label for="customermobile" class="col-lg-4 control-label">Customer Mobile </label>
<div class="col-lg-8">
<input class="form-control" id="customermobile" name="customermobile" type="text" >
</div>
</div>

<button type="reset" id="clearbutton" class="btn btn-default btn-sm ">Clear</button><button id="submit" type="submit" name="submit" class="btn btn-success btn-sm pull-right">Continue</button>

</form>


php code

$sql_1 = "SELECT ticket_id FROM ticket_details WHERE ticket_id = '".$ticket_id."'";
$res_1 = mysql_query($sql_1);
$row = mysql_fetch_assoc($res_1);
$get_id=$row['ticket_id'];
$ticket_status = '1';

if(isset($_POST['A1'])){

$seat_no = $_POST['A1'];

if (!$get_id==$ticket_id){
$sql_2 = "INSERT INTO ticket_details (ticket_id,".$seat_no.") VALUES('".$ticket_id."','".$ticket_status."')";
$res_2 = mysql_query($sql_2);
if(!$res_2) return 1;
return 99;
}
if ($get_id==$ticket_id){
$sql_3 = "UPDATE ticket_details SET ".$seat_no." = '".$ticket_status."' WHERE ticket_id = '".$ticket_id."'";
$res_3 = mysql_query($sql_3);
if(!$res_3) return 1;
return 99;
}
}
if(isset($_POST['A2'])) {
$seat_no = $_POST['A2'];

if (!$get_id==$ticket_id){
$sql_2 = "INSERT INTO ticket_details (ticket_id,".$seat_no.") VALUES('".$ticket_id."','".$ticket_status."')";
$res_2 = mysql_query($sql_2);
if(!$res_2) return 1;
return 99;
}
if ($get_id==$ticket_id){
$sql_3 = "UPDATE ticket_details SET ".$seat_no." = '".$ticket_status."' WHERE ticket_id = '".$ticket_id."'";
$res_3 = mysql_query($sql_3);
if(!$res_3) return 1;
return 99;
}
}
if(isset($_POST['A3'])){
$seat_no = $_POST['A3'];

if (!$get_id==$ticket_id){
$sql_2 = "INSERT INTO ticket_details (ticket_id,".$seat_no.") VALUES('".$ticket_id."','".$ticket_status."')";
$res_2 = mysql_query($sql_2);
if(!$res_2) return 1;
return 99;
}
if ($get_id==$ticket_id){

$sql_3 = "UPDATE ticket_details SET ".$seat_no." = '".$ticket_status."' WHERE ticket_id = '".$ticket_id."'";
$res_3 = mysql_query($sql_3);
if(!$res_3) return 1;
return 99;
}
}

Answer

It appears that all possible branches within if(isset($_POST['A1'])){ end with a return. That means that execution can never reach if(isset($_POST['A2'])) {.

Comments