first,I have table display from database, in each row it has update button.
second, i have a four (4) collapsible select option form.
third, the select option form has value from database. this value is also present in the column on the table above(first).
Now what i want is when i update the value from the row on the table, the collapsible form will open then the value from the table will display on the select option form.
Here's my code. the code below cant open the collapsible form and display the value on the select option form.
displaytable.php
<?php
$output='';
$noresult='';
if (isset($_POST['search']))
{
$globalpid = $_POST['search'];
$query = mysql_query("SELECT * FROM transaction where patientid ='$globalpid' order by trandate asc") or die ("could not search");
$count = mysql_num_rows($query);
$globalpid = mysql_real_escape_string($globalpid);
if($count == '' && $countname==0)
{
?>
<?php require_once 'search.php'; ?>
<div class="container" style="padding-left:30px">
<br><p><font color="#0B3861"><?php echo "There was no search results!"; ?> </font>
</div>
</div>
<?php }else{
?>
<?php
$total = '';
$add=mysql_query("SELECT SUM(tranamount) from transaction where patientid = $globalpid");
while($row=mysql_fetch_array($add))
{
$totalamount=$row['SUM(tranamount)'];
}
require_once 'transactionheadermenu.php';
?>
<div class="container" style="padding-top:0px; padding-left:30px; padding-right:30px;">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title"><font color="#2B547E"><?php echo "$outputname";?></font></h3></div>
<div class="panel-body">
<?php require_once 'billpatientquery.php';?>
<?php
echo "<table class='table table-hover';>
<tr>
<td style='border:1px solid; color:gray' width='145px' align='center'>Patient ID</td>
<td style='border:1px solid; color:gray' width='145px' align='center'>Date</td>
<td style='border:1px solid; color:gray' width='600px' align='center'>Item / Description</td>
<td style='border:1px solid; color:gray' width='90px' align='center'>Quantity</td>
<td style='border:1px solid; color:gray' width='90px' align='center'>Price</td>
<td style='border:1px solid; color:gray' width='150px' align='center'>Amount</td>
<td style='border:1px solid; color:gray' width='30px' align='center'>Update</td>
<td style='border:1px solid; color:gray' width='30px' align='center'>Delete</td>
</tr>";
while($row = mysql_fetch_array($query))
{
echo "
<tr>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['patientid']."</td>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['trandate']."</td>
<td style='border:1px solid; color:gray' width='600px'>".$row['trandescription']."</td>
<td style='border:1px solid; color:gray' width='90px' align='center'>".$row['tranquantity']."</td>
<td style='border:1px solid; color:gray' width='90px' align='right'>".number_format($row['tranunitprice'],2)."</td>
<td style='border:1px solid; color:gray' width='150px' align='right'>".number_format($row['tranamount'],2)."</td>
<td style='border:1px solid; color:gray'><a href='updatebillindex.php?update=$row[id]'>update</a></td>
<td style='border:1px solid; color:gray'><button class='btn btn-default btn-sm';><a href='updatebillindex.php?update=$row[0]'>edit
<span class='glyphicon glyphicon-trash'></span></a></button></td>
</tr> ";
}
echo "</table>";
?>
</div>
</div>
</div>
<?php }
} ?>
updatebillindex.php
?php
if (isset($_GET['update']))
//
{
$id = $_GET['update'];
// //$tranid = $_POST['update'];
//$patientid = $_POST['update'];
//$trandate = $_POST['update'];
//$getname = $_POST['update'];
$query = mysql_query("SELECT * FROM transaction where id = '$id'") or die ("could not search");
$count = mysql_num_rows($query);
while ($rows = mysql_fetch_array($query)) {
$id = $rows['id'];
$tranid = $rows['tranid'];
$trandate = $rows['trandate'];
$patientid = $rows['patientid'];
$transactiontype = $rows['transactiontype'];
$trandescription = $rows['trandescription'];
$tranquantity = $rows['tranquantity'];
$tranunitprice = $rows['tranunitprice'];
$tranamount =$rows['tranamount'];
$gettrandescription = $rows['trandescription'];
}
}
if (isset($_POST['selectmedicine'])) {
$gettrandescription=$_POST['medicineid'];
}
if (isset($_POST['selectroomquantity'])) {
$tranquantity=$_POST['quantity'];
}
?>
<script type="text/javascript">
$('#collapseone').collapseone({
toggle: true
});
</script>
<option value="<?php echo $trandescription; ?>" <?php if($trandescription==$gettrandescription){ echo "selected";} ?> ><?php echo $gettrandescription; ?></option>
<option value="<?php echo $tranquantity; ?>" <?php if($tranquantity==$tranquantity){ echo "selected";} ?> ><?php echo $tranquantity; ?></option>
<form action="billindex.php" method="POST">
<input type="hidden" name="id" value="<?php echo "$id"; ?>">
<input type="hidden" name="tranid" value="<?php echo "$tranid"; ?>">
<input type="hidden" name="patientid" value="<?php echo "$patientid"; ?>">
<input type="hidden" name="trandate" value="<?php echo "$trandate"; ?>">
<input type="hidden" name="transactiontype" value="<?php echo "$transactiontype"; ?>">
<input type="hidden" name="trandescription" value="<?php echo "$trandescription"; ?>">
<input type="hidden" name="tranquanity" value="<?php echo "$tranquantity"; ?>">
<input type="hidden" name="tranunitprice" value="<?php echo "$tranunitprice"; ?>">
<input type="hidden" name="tranamount" value="<?php echo "$tranamount"; ?>">
<input type="submit" name="update" value="Update">
</form>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Medicine
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<form action="transaction.php" method="POST">
<div class="col-md-6">
<div class="panel panel-info">
<div class="panel-heading"><h7>Medicine Type : </h7></div>
<div class="panel-body">
<select name="selectmedicine" class="form-control col-sm-4" id="medicinename">
<option id="0" style="width:100px"></option>
<?php
$medicine = mysql_query("SELECT * FROM medicine");
while ($row = mysql_fetch_array($medicine)) {
echo '<option id="' . $row['medicinename'] . '"';
echo ' value="' . $row['medicineid'] . '"';
if($row['medicineid'] == $row['medicinename']) {
echo ' selected="selected"';
}
echo '>';
echo $row['medicinename'];
echo '</option>';
}
?>
</select>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-info">
<div class="panel-heading panel-height:20px":><h7>Quantity : </h7></div>
<div class="panel-body">
<select name="selectmedicinequantity" class="form-control col-md-4" id="quantityname">
<option id="0" style="width:100px"></option>
<?php
$medicinequantity = mysql_query("SELECT * FROM quantity");
while ($displayquantity = mysql_fetch_array($medicinequantity)) {
$quantityid = $displayquantity['id'];
$quantityname = $displayquantity['quantityname'];
//$quantityprice = $displayquantity['quantityprice'];
?>
<option id=" <?php echo $displayquantity['quantityid']; ?>"><?php if($displayquantity['quantityid'] == $displayquantity['quantityname']) echo 'selected="selected"'; ?><?php echo $displayquantity['quantityname'] ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
Related
how to insert select option value in database using checkbox?When I click checkbox and click enroll button ,select option doesn't inserting selected value.I have 3 options(Regular,Retake,Recourse) in "examtype" table but when I choose more than one subject select option not working perfectly. Here is my code...
here is my select option image
<?php
if (isset($_POST['enroll']))
{
if (!empty($_POST['chk1']))
{
if (isset($_POST['et']))
{
$roll_no = $_SESSION['roll_no'];
//$selectbox1 = $_POST['et'];
foreach($_POST['chk1'] as $checkbox1)
{
foreach($_POST['et'] as $selectbox1)
//for($i=0;$i<sizeof($selectbox1);$i++)
$values = explode("|" , $checkbox1);
$values1= explode("|" , $selectbox1);
$course_id= $values[0];
$semester= $values[1];
$course_name= $values[2];
$selectbox1=$values1[0];
$sql="INSERT INTO pendingcourse(roll_no,course_id,semester,course_name,exam_type,status) VALUES('$roll_no','$course_id','$semester','$course_name','$selectbox1',0)";
$stmt = $connect->prepare($sql);
$stmt->execute();
$checkbox1='';
$selectbox1='';
}
header("location:coursetable.php");
}
}
}
?>
<form action="coursetable.php" method="post" enctype="multipart/form-data">
<div class="container mt-3" >
<div class="accordion mb-4" id="accordionExample" >
<div class="accordion-item" style="background-color: rgb(0, 225, 255);">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button collapsed fw-bold" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne" style="background: #AAFFA9;">
1st Semester
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse" aria-labelledby="headingOne" >
<div class="accordion-body">
<table class="table table-bordered border-primary text-center">
<thead>
<tr>
<th scope="col-1">Course Id</th>
<th scope="col-1">Semester</th>
<th scope="col-7">Course</th>
<th scope="col-1">Exam Type</th>
<th scope="col-1">Select</th>
<th scope="col-2">Result</th>
</tr>
</thead>
<tbody>
<?php
$stmt = $connect->query("SELECT course_id,semester,course_name FROM coursetable Where semester = '1st' ");
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($rows as $row)
{
$course_id = $row['course_id'];
$semester = $row['semester'];
$course_name = $row['course_name'];
?>
<tr>
<td scope="row"> <?php echo $course_id?></td>
<td > <?php echo $semester ?></td>
<td ><?php echo $course_name ?></td>
<td>
<select name="et[]" class="form-select form-select-sm" aria-label=".form-select-sm example">
<?php
$stmt1 = $connect->query("SELECT * from examtype");
$rows1 = $stmt1->fetchAll(PDO::FETCH_ASSOC);
foreach($rows1 as $row1) {
?>
<option value="<?php echo $row1['exam_type']; ?>"><?php echo $row1['exam_type']; ?></option>
<?php
}
?>
</select>
</td>
<td>
<input type="checkbox" name="chk1[]" value="<?php echo $row['course_id']?>|<?php echo $row['semester']?>|<?php echo $row['course_name']?>|<?php echo $row1['exam_type']?>">
<label class="form-check-label" for="flexCheckDefault">
</label>
</td>
<td></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-2 col-xs-6 offset-md-5 mb-3">
<button type="submit" name="enroll" class="btn btn-warning mt-2">Enroll</button>
</div>
</div>
</div>
</form>
Place the input field inside a form and add
enctype="multipart/form-data"
<select name="et[]" class="form-select form-select-sm" aria-label=".form-select-sm example" multiple>
try this
add multiple in select
SOLVED:
<?php
if (isset($_POST['enroll']))
{
if (!empty($_POST['chk1']))
{
if (!empty($_POST['et']))
{
$roll_no = $_SESSION['roll_no'];
$selectbox1 = $_POST['et'];
$selectbox11=implode(',',array_filter($selectbox1));
$i=0;
foreach($_POST['chk1'] as $checkbox1)
{
$selectbox111 = array_diff(explode(",", $selectbox11),array(""));
$selectbox1111 = $selectbox111[$i];
$values = explode("|" , $checkbox1);
$course_id= $values[0];
$semester= $values[1];
$course_name= $values[2];
$sql="INSERT INTO pendingcourse(roll_no,course_id,semester,course_name,exam_type,status) VALUES('$roll_no','$course_id','$semester','$course_name','$selectbox1111',0)";
$stmt = $connect->prepare($sql);
$stmt->execute();
$checkbox1='';
$i++;
}
}
}
}
?>
I have developed shopping cart in PHP but while inserting cart data into the database I got an error of undefined index. Can anybody please tell me how do I solve it? I have called all the three values using POST method and these all are also present in the database still i am getting this error.Why?
Code:
reviewcart.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "midata";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$code=$_POST['code'];
$quantity=$_POST['quantity'];
$sql = "INSERT INTO order_final (name, code, quantity)
VALUES ('$name', '$code', '$quantity')";
if ($conn->query($sql) === TRUE) {
}
else{
}
}
else{ echo 'query doesnt execute';
}
?>
<div class="container">
<?php
session_start();
require_once("dbcontroller.php");
$db_handle = new DBController();
if(!empty($_GET["action"])) {
switch($_GET["action"]) {
case "remove":
if(!empty($_SESSION["cart_item"])) {
foreach($_SESSION["cart_item"] as $k => $v) {
if($_GET["code"] == $k)
unset($_SESSION["cart_item"][$k]);
if(empty($_SESSION["cart_item"]))
unset($_SESSION["cart_item"]);
}
}
break;
case "empty":
unset($_SESSION["cart_item"]);
break;
}
}
?>
<div class="c-layout-sidebar-content ">
<!-- BEGIN: PAGE CONTENT -->
<div class="c-content-title-1 c-margin-t-30">
<h3 class="c-font-uppercase c-font-bold c-center ">Place Order</h3>
<div class="c-content-panel">
<div class="c-body">
<div class="row">
<div class="col-md-12">
<table class="table table-condensed">
<div id="shopping-cart">
<div class="txt-heading">Shopping Cart <a id="btnEmpty" href="reviewcart.php?action=empty">Empty Cart</a></div>
<?php
if(isset($_SESSION["cart_item"])){
$item_total = 0;
?>
<table class="col-md-12" cellpadding="10" cellspacing="1" >
<tbody class="col-md-12">
<tr>
<form action="" method="post">
<th class="col-md-3" style="text-align:center;"><strong>Name</strong></th>
<th class="col-md-3" style="text-align:center;"><strong>Code</strong></th>
<th class="col-md-3" style="text-align:center;"><strong>Quantity</strong></th>
<th class="col-md-3" style="text-align:center;"><strong>Price</strong></th>
<th class="col-md-3" style="text-align:center;"><strong>Action</strong></th>
</tr>
<?php
foreach ($_SESSION["cart_item"] as $item){
?>
<tr>
<td style="text-align:center;border-bottom:#F0F0F0 1px solid;"><strong><?php $name=$_POST['name'] ; echo $item["name"]; ?></strong></td>
<td style="text-align:center;border-bottom:#F0F0F0 1px solid;"><?php $code=$_POST['code'] ; echo $item["code"]; ?></td>
<td style="text-align:center;border-bottom:#F0F0F0 1px solid;"><?php $quantity=$_POST['quantity'] ; echo $item["quantity"]; ?></td>
<!-- <td style="text-align:center;border-bottom:#F0F0F0 1px solid;"><?php $price=$_POST['price'] ; echo $price ?></td> -->
<td style="text-align:center;border-bottom:#F0F0F0 1px solid;">Remove Item</td>
</tr>
<!-- <?php
$item_total += ($item["price"]*$item["quantity"]);
}
?>
-->
<tr>
<td colspan="5" align=right><input type="submit" name="submit" value="submit" /></td>
</tr></form>
</tbody>
</table>
<?php
}
?>
</div>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
If we want to post any data via form mean we must want to use input tag then only we can accept it values on global arrays like $_POST, $_GET, $_FILES.
<tr>
<td style="text-align:center;border-bottom:#F0F0F0 1px solid;">
<strong><?php echo $item["name"]; ?></strong>
<input type="hidden" name="name" value="<?php echo $item['name']?>">
</td>
<td style="text-align:center;border-bottom:#F0F0F0 1px solid;">
<?php echo $item["code"]; ?>
<input type="hidden" name="code" value="<?php echo $item['code']?>">
</td>
<td style="text-align:center;border-bottom:#F0F0F0 1px solid;">
<?php echo $item["quantity"]; ?>
<input type="hidden" name="quantity" value="<?php echo $item['quantity']?>">
</td>
<!-- <td style="text-align:center;border-bottom:#F0F0F0 1px solid;">
<?php $price=$_POST['price'] ; echo $price ?>
</td> -->
<td style="text-align:center;border-bottom:#F0F0F0 1px solid;">
<a href="reviewcart.php?action=remove&code=<?php echo $item["code"]; ?>" class="btnRemoveAction">
Remove Item
</a>
</td>
</tr>
I'm developing website which advertises used cars for sell in codeigniter. I want to do hit counter for each news by method in controller. When user clicks to news the modal of this news opens and it should add 1 to my hitCounter column in database. I tried many codes and ways to do this but it is not working. If someone please can suggest what to do in this case. Thanks in advance!
Here my controller's method code:
public function clickCounter($id)
{
$this->news_model->set_counter($id);
}
Here my views code:
<?php foreach ($news as $news_item): ?>
<div class="font-icon-list col-lg-3 col-md-3 col-sm-4 col-xs-12" style="padding: 15px;" onclick="document.getElementById('<?php echo $news_item['id']; ?>').style.display='block'; ">
<div class="font-icon-detail"><img src="<?php echo base_url(); echo "images/thumb/images/"; echo $news_item['image_path']; ?>" alt="" style=" max-width: 220px; height:100%;">
<input type="text" value="<?php echo $news_item['location']; echo " - "; echo $news_item['price']; ?>">
<input type="text" value="<?php echo $news_item['telno']; ?>">
</div>
</div>
<div id="<?php echo $news_item['id']; ?>" class="w3-modal">
<div class="w3-modal-content w3-animate-zoom" >
<header class="w3-container">
<span onclick="document.getElementById('<?php echo $news_item['id']; ?>').style.display='none'"
class="w3-closebtn">×</span>
</header>
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12" style="background-color: white; padding:0;">
<table class="table table-hover table-striped" style="white-space:wrap; overflow:hidden;">
<tr>
<td colspan="2" class="text-center"><?php echo $news_item['title']; ?></td>
</tr> <tr>
<td>Сана</td><td><?php echo $news_item['date']; ?></td>
</tr>
<tr >
<td>Нархи</td><td><?php echo $news_item['price']; ?></td>
</tr>
<tr>
<td>Исми ва шарифи</td><td><?php echo $news_item['name']; ?></td>
</tr>
<tr>
<td>Телефон рақам</td><td><?php echo $news_item['telno']; ?></td>
</tr>
<tr>
<td colspan="2" class="text-center">Қўшимча маълумот:</td>
</tr>
<tr>
<td class="text-justify" colspan="2"><?php echo $news_item['info']; ?></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
Here my model code:
public function set_counter($id)
{
$sql = "SELECT * FROM avto WHERE id = ?" ;
$query = $this->db->query($sql, $id);
if ($query->num_rows() > 0) {
foreach ($query->result_array() as $row) {
$data['hitCounter'] = $row['hitCounter'];
}
$numHits= $data['hitCounter'];
$numHits = $numHits + 1;
$data = array(
'hitCounter' => $numHits,
);
$this->db->where('id', $id);
$this->db->update('avto', $data);
}
return false;
}
Step 1: Call controller function onClick
<button type="button" class="btn btn-success"
onclick="<?php echo base_url()?>controller/function">Click Here</button>
Step 2: In Controller define respective function and add update query..
you have to update count in table because in real-time counter can't be stored in session as there are multiple users are using website
now add table named as tbl_count and apply below query
$qry = "UPDATE `tbl_count` SET `hits`=`hits` +1 WHERE `news_id` = '".$news_id."'";
Your model function should be something like this
public function set_counter($id)
{
if($id>0)
{
$sql = "UPDATE avto SET hitCounter = hitCounter + 1 WHERE id = ".$id ;
$this->db->query($sql);
}
}
Just want to know how to find the match value on the dropdown list and display the value as current selected for update.
this is my table query and displayed on page with update link beside each row. All update link is working and the value displayed on hidden textbox. My problem is just on one column $trandescription, this will be post on dropdown.
this is my display table.
while($row = mysql_fetch_array($query))
{
echo "
<tr>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['patientid']."</td>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['trandate']."</td>
<td style='border:1px solid; color:gray' width='600px'>".$row['trandescription']."</td>
<td style='border:1px solid; color:gray' width='90px' align='center'>".$row['tranquantity']."</td>
<td style='border:1px solid; color:gray' width='90px' align='right'>".number_format($row['tranunitprice'],2)."</td>
<td style='border:1px solid; color:gray' width='150px' align='right'>".number_format($row['tranamount'],2)."</td>
<td style='border:1px solid; color:gray'><a href='updatebillindex.php?update=$row[id]'>update</a></td>
<td style='border:1px solid; color:gray'><button class='btn btn-default btn-sm';><a href='updatebillindex.php?update=$row[0]'>edit
<span class='glyphicon glyphicon-trash'></span></a></button></td>
</tr> ";
this is my update page
<?php
if (isset($_GET['update']))
{
$id = $_GET['update'];
$query = mysql_query("SELECT * FROM transaction where id = '$id'") or die ("could not search");
$count = mysql_num_rows($query);
while ($rows = mysql_fetch_array($query)) {
$id = $rows['id'];
$tranid = $rows['tranid'];
$trandate = $rows['trandate'];
$patientid = $rows['patientid'];
$transactiontype = $rows['transactiontype'];
$trandescription = $rows['trandescription'];
$tranquantity = $rows['tranquantity'];
$tranunitprice = $rows['tranunitprice'];
$tranamount =$rows['tranamount'];
$gettrandescription = $rows['trandescription'];
}
}
?>
<form action="billindex.php" method="POST">
<input type="hidden" name="id" value="<?php echo "$id"; ?>">
<input type="hidden" name="tranid" value="<?php echo "$tranid"; ?>">
<input type="hidden" name="patientid" value="<?php echo "$patientid"; ?>">
<input type="hidden" name="trandate" value="<?php echo "$trandate"; ?>">
<input type="hidden" name="transactiontype" value="<?php echo "$transactiontype"; ?>">
<input type="text" name="trandescription" value="<?php echo "$trandescription"; ?>">
<input type="hidden" name="tranquanity" value="<?php echo "$tranquantity"; ?>">
<input type="hidden" name="tranunitprice" value="<?php echo "$tranunitprice"; ?>">
<input type="hidden" name="tranamount" value="<?php echo "$tranamount"; ?>">
<input type="submit" name="update" value="Update">
</form>
<?php
echo "$trandescription"; // find the match value on dropdown list and display this value.
?>
this is my dropdown list on the update page
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Medicine
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<form action="transaction.php" method="POST">
<div class="col-md-6">
<div class="panel panel-info">
<div class="panel-heading"><h7>Medicine Type : </h7></div>
<div class="panel-body">
<select name="selectmedicine" class="form-control col-sm-4" id="medicinename">
<option id="0" style="width:100px"></option>
<?php
$medicine = mysql_query("SELECT * FROM medicine");
while ($row = mysql_fetch_array($medicine)) {
echo '<option id="' . $row['medicinename'] . '"';
echo ' value="' . $row['medicineid'] . '"';
if($row['medicineid'] == $row['medicinename']) {
echo ' selected="selected"';
}
echo '>';
echo $row['medicinename'];
echo '</option>';
}
?>
</select>
</div>
</div>
</div>
I have a very simple IF statement that worked for me a week ago, but mysteriously doesn't work for me now. I have a field when selected, creates an extra query.
The problem is, the doc is completely skipping over my if statement like it doesn't even exist
Here's the WHOLE CODE
<body id="bdy" onload="javascript:fg_hideform('fg_formContainer','fg_backgroundpopup');">
<div class="container_22" id="container">
<div id="rootDiv">
<div style="background-color: rgb(255, 255, 255);"
id="wrapper">
<div class="main">
<div id="mainMiddle" class="main-middle">
<div id="content" class="wide-content"
style="position: relative; width: 990px; background-color: rgb(255, 255, 255);
display: inline; margin-left:
15px;">
<span id="cntntMiddle_bannerTop"></span><!-- =search-bar | start -->
<div id="cntntMiddle_SearchBoxContainer"
style="margin-top: 20px; padding-left: 20px;">
<form action="search.php" class="search-bar" method="GET">
<h3>Search</h3>
<fieldset>
<div class="ctrlHolder inline">
<input type="checkbox" name="r" id="r" value="y">
Return Flight?
</div>
<div class="ctrlHolder
inline">
<input type="hidden" class="fnc-direction" id="curusd" name="Currency" value="USD" /> </div> <div id="trip-1" class="fnc-trip first"> <h6 ><span id="flight1">Departing Flight</span> </h6> <div
class="ctrlHolder"> <label for="from-1"> <span class="left">From</span> <span class="right">(City or Airport)</span> </label> <?php
$autocomplete1 = array();
mysql_connect('localhost', '', '');
mysql_select_db('');
$sql = "SELECT distinct rout_from FROM search_v ORDER BY rout_from ASC";
$r = mysql_query($sql);
while ($row = mysql_fetch_array($r))
{
$autocomplete1[] = $row['rout_from'];
}
?><input id="newsearch1" name="departure_label">
</div> <div class="ctrlHolder"><label for="from-1"> <span class="left">To</span> <span class="right">(City or Airport)</span> </label> <?php
$autocomplete = array();
mysql_connect('localhost', '', '');
mysql_select_db('');
$sql = "SELECT distinct rout_to FROM search_v ORDER BY rout_to ASC";
$r = mysql_query($sql);
while ($row = mysql_fetch_array($r))
{
$autocomplete[] = $row['rout_to'];
}
?><input id="newsearch" name="arrival_label"> </div> <div class="ctrlHolder"> <label for="leave-1">Depart</label>
<input type="text" id="f" name="txtDate1"/> </div> <div class="ctrlHolder"> <label for="leave-2">Arrive</label>
<input type="text" id="t" name="txtDate2"/></div> </div> </fieldset> <fieldset class="travelers">
<legend>Travelers
</legend>
<div class="ctrlHolder inline-select clearfix">
<div class="field">
<label for="adults">
<br />
Passengers</label>
<select
name="ddlPAxADT" id="ddlPaxADT">
<option selected="selected"
value="1">1</option><option value="2">2</option><option
value="3">3</option><option value="4">4</option><option value="5">5</option>
</select>
</div>
<br>
</div>
</fieldset>
<div class="submit-wrap
clearfix">
<button class="btn-reset" type="reset">
Reset
</button>
<input
name="submit" class="btn-search" type="submit" />
</div>
</form>
</div>
<div id="cntntMiddle_search-results" class="search-results">
<span id="cntntMiddle_lblResults"> <h2>Search Results</h2> <h3>Showing <span id="cntntMiddle_ctl01_lblFlightFilter">all
results</span></h3>
<?php
mysql_connect('localhost', '', '');
mysql_select_db('');
$search = $_GET['search'];
$sfrom = $_GET['departure_label'];
$sto = $_GET['arrival_label'];
$sfromda = $_GET['txtDate1'];
$stoda = $_GET['txtDate2'];
$padt = $_GET['ddlPaxADT'];
$currency = $_GET['Currency'];
$ret = $_GET['r'];
if ($ret!='y') {
$sql1 = mysql_query("SELECT * FROM search_v WHERE rout_to='$sfrom' AND rout_from='$sto' AND date_avialable='$stoda'") or die(mysql_error());
$runrows1 = mysql_fetch_array($sql1);
$flightid1 = $runrows1['flight_id'];
$aseats1 = $runrows1['seats_avialable'];
$todate1 = strftime("%b %d, %Y %l:%M %p" ,strtotime($runrows1['to_date']));
$date1 = strftime("%b %d, %Y %l:%M %p" ,strtotime($runrows1['date_avialable']));
$from1 = $runrows1['rout_from'];
$to1 = $runrows1['rout_to'];
$acost1 = $runrows1['adult_cost'];
$ccost1 = $runrows1['child_cost'];
$cur1 = $runrows1['currency'];
$oth1 = $runrows1['other_cost'];
$totalcost1= $acost1+$oth1;
$pr1 = $flightid1+5;
}
//echo outconstruct
$sql = mysql_query("SELECT * FROM search_v WHERE currency='$currency' AND
rout_to='$sto' AND rout_from='$sfrom' AND DATE_FORMAT(date_avialable,'%Y-%m-%d')
between'".$sfromda."' and '".$stoda."' LIMIT 10") or die(mysql_error()) ;
while ( $runrows = mysql_fetch_array($sql))
{
//get data
$flightid = $runrows['flight_id'];
$aseats = $runrows['seats_avialable'];
$todate = strftime("%b %d, %Y %l:%M %p" ,strtotime($runrows['to_date']));
$date = strftime("%b %d, %Y %l:%M %p" ,strtotime($runrows['date_avialable']));
$from = $runrows['rout_from'];
$to = $runrows['rout_to'];
$acost = $runrows['adult_cost'];
$ccost = $runrows['child_cost'];
$cur = $runrows['currency'];
$oth = $runrows['other_cost'];
$totalcost= $acost+$oth;
$pr = $flightid+5;
echo "";
?>
<?PHP
include('popup/contactform-code.php');
?>
<ul class="result-list clearfix">
<li class="item clearfix">
<span
id="cntntMiddle_ctl01_rptmain_lblFromt_0">
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="price">Price<?php echo $ret; ?></th>
<th>From</th>
<th>To</th>
<th>Depart</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="6">
<div class="select-wrap">
<p class="seats">
<strong><?php echo $aseats; ?></strong><span>seats
left</span><em>at this price</em>
</p> <a href='javascript:fg_popup_form("fg_formContainer","fg_form_InnerContainer","fg_backgroundpopup");'
><img border='0' src='images/select_flight.png' width='121' height='34' /></a>
</div></td>
</tr>
</tfoot>
<tbody>
<tr>
<td class="price" rowspan="2"><a
style="font-weight: bold; cursor: pointer; text-decoration: none;"
herf="#" onclick='return ray.ajax("#");'><span
style="font-size: 24px; font-weight: bold;"><?php echo $totalcost; ?></span><span
style="font-size: 11px; margin-top: 2px; display: block; color: rgb(255, 255,
255); text-align: center; font-
weight: normal;">per
person</span><span
style="font-size: 12px; margin-top: 2px; display: block; color: rgb(255, 255,
255); text-align: center; font-
weight: normal;">(with fees)</span></a></td>
<td><?php echo $from; ?></td>
<td><?php echo $to ?></td>
<td style="padding-right: 2px;"><?php echo $date; ?></td>
</tr>
<tr>
<td><?php echo $to1; ?></td>
<td><?php echo $from1 ?></td>
<td style="padding-right: 2px;"><?php echo $date1; ?></td>
</tr>
</tbody>
</table> </span><a
id="cntntMiddle_ctl01_rptmain_lblResultDetails1_0" title="1"
href="javascript:__doPostBack('ctl00$cntntMiddle$ctl01$rptmain
$ctl00$lblResultDetails1','')"
style="color: Black;"></a><a class="close"
href="#">Close</a>
<div class="info clearfix">
<div class="info clearfix">
<h4>Departing Flight</h4>
<ul class="clearfix">
<li>
<h5><?php echo $from; ?> to <?php echo $to; ?> <?php echo $date; ?></h5>
<ul>
<li>
</li>
<li>
<strong>Flight #</strong> - <?php echo $flightid; ?>
</li>
<li>
<strong>Departure Time – </strong>
<?php echo $date; ?>
</li>
</ul>
</li>
</ul>
<ul>
<li style="padding-top: 5px;">
<span
style="color: rgb(212, 22, 13); font-weight: bold; font-size: 11px; text-
decoration: none;"> Fare Breakdown</span>
</li>
</ul>
<table class="more">
<tbody>
<tr>
<th>Passenger</th>
<th>Fare</th>
<th> Taxes and Fees</th>
<th>Qty</th>
<th>Total Cost</th>
</tr>
</tbody>
<tbody>
<tr>
<td>Adult</td>
<td
style="color: rgb(100, 100, 100); font-size: 11px; font-weight: bold;"><?php
echo $acost; ?></td>
<td><?php echo $oth; ?></td>
<td id="paxAdtTd">1</td>
<td><?php echo $acost; ?></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>Cost of Sale(<?php echo $cur; ?>)</td>
<td> </td>
<td
style="color: rgb(100, 100, 100); font-size: 14px; font-weight: bold;"><?php
echo $totalcost; ?></td>
</tr>
</tbody>
</table>
<br />
<span style="font-weight: bold; padding-top: 10px;"> *Additional airline fees for baggage may apply</span>
<div class="select-wrap">
<p class="seats">
<strong><?php echo $aseats; ?></strong><span>seats
left</span><em>at this price</em>
</p>
<button class="btn-select" type="button" id="start">
Select
Flight
</button>
</div>
</li>
</ul> </ul>
</ul>
<?php ;}?>
</div>
</div>
I think it's because of trailing newline character. So, before you actually do if($ret != 'y') just trim it $ret = trim($ret). give it a try.
$ret = $_GET['r'];
$ret = trim($ret);
if ($ret!='y')
{
// rest of your code
}
Try something like:
<?php
$ret = $_GET['r'];
if($ret != "y") {
echo "Yay!";
} else {
echo ":(";
}
?>
<html>
<head>
</head>
<body>
<form method="get" action="search.php">
<input type="checkbox" value="y" name="r" />Submit Query<br />
<input type="submit" value="Submit" name="submit" />
</form>
</body>
</html>