Table sorting and searching text filed is not working properly using bootstrap 3. I am basically developing a query builder and making a dynamic table of my data but table sorting and searching is not working properly. Data display accurately but the table sort and search text box do not display data.
<?php
ini_set( "display_errors", 0);
include "include.php";
include "connect_to_mysql.php";
$table='Genomics_data_ncbi';
$display = array();
$qu_mul="";
?>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript">
function formValidation(form)
{
var ccc = document.getElementById("first_box").value;
if(ccc == "") {
alert("Please enter a keyword !!!");
return false;
}
}
var intTextBox=0;
//FUNCTION TO ADD TEXT BOX ELEMENT
function addElement()
{
intTextBox = intTextBox + 1;
var contentID = document.getElementById("content");
var newTBDiv = document.createElement("div");
newTBDiv.setAttribute("id","strText"+intTextBox);
newTBDiv.innerHTML = "<select name='op[]'><option value='and'>AND</option> <option value='or'>OR</option> </select><select name='fieldsi[]'><option value='all'>All Fields</option><option value='' align='center' style='background-color: #FFCCCC'>Genome Information</option><option value='Gene_id'>Gene_id</option><option value='Gene_name'>Gene_name</option><option value='Gene_product'>Gene_product</option><option value='Function_of_proteins'>Function_of_proteins</option><option value='Protein_id'>Protein_id</option><option value='Localization_of_proteins'>Localization_of_proteins</option><option value='Strain_id'>Strain_id</option></select><select name='fieldsi_op[]'><option value='like'>LIKE</option><option value='not like'>Not LIKE</option><option value='equal'>Equal to</option><option value='not_equal'>Not equal to</option><option value='='> = </option><option value='!='> != </option><option value='<='> <= </option><option value='>='> >= </option><option value='<'> < </option><option value='>'> > </option></select> <input type='text' id='" + intTextBox + "' name='keyword[]'>";
contentID.appendChild(newTBDiv);
}
//FUNCTION TO REMOVE TEXT BOX ELEMENT
function removeElement()
{
if(intTextBox != 0)
{
var contentID = document.getElementById("content");
contentID.removeChild(document.getElementById("strText"+intTextBox));
intTextBox = intTextBox-1;
}
}
</script>
<!--<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
<p>
<button type = "button" class = "btn btn-default">
<span class = "glyphicons-halflings-regular.eot"></span>
</button>
<button type = "button" class = "btn btn-default">
<span class = "glyphicons-halflings-regular.ttf"></span>
</button>
<button type = "button" class = "btn btn-default">
<span class = "glyphicons-halflings-regular.woff"></span>
</button>
<button type = "button" class = "btn btn-default">
<span class = "glyphicons-halflings-regular.svg"></span>
</button>
<link href="tablesort/css/glyphicons-halflings-regular.eot" rel="stylesheet">
<link href="tablesort/css/glyphicons-halflings-regular.ttf" rel="stylesheet">
<link href="tablesort/css/glyphicons-halflings-regular.woff" rel="stylesheet">
<link href="tablesort/css/glyphicons-halflings-regular.svg" rel="stylesheet">-->
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet">
<script src="tablesort/js/jquery-3.3.1.js" type="text/javascript"></script>
<script src="tablesort/js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="tablesort/js/dataTables.bootstrap.min.js" type="text/javascript"></script>
<link href="tablesort/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="tablesort/css/dataTables.bootstrap.min.css" rel="stylesheet" type="text/css"/>
<script>
$(document).ready(function() {
$('#example').DataTable();
} );
</script>
</head>
<br>
<br>
<br>
<br>
<font color="#3d4983" face="Verdana" size="3"><b>Query Builder</b></font>
<br>
<p align='justify'>Users may build complex queries using the logical operators 'AND' and 'OR'. Each sub-query can be built using other operators such as LIKE, NOT LIKE, EQUAL and NOT EQUAL TO while dealing with strings like
words or letters and =, !=, <=, >=, < and > while dealing with numerical values. The Query builder aids to the flexibility of performing search on a number of fields simultaneously.</p>
<br>
<form name='form1' action="<?=$_SERVER['PHP_SELF']; ?>" method='post' onsubmit="return formValidation(this);">
<select name='fieldsi[]'>
<option value='all'>All Fields</option>
<option value='' style="background-color: #FFCCCC">Gene Information</option>
<option value='Gene_id'>Gene id</option>
<option value='Gene_name'>Locus tag</option>
<option value='Gene_product'> Gene product</option>
<option value='Function_of_proteins'> Protein function</option>
<option value='Protein_id'> Protein ID</option>
<option value='Localization_of_proteins'> Localization of protein</option>
<option value='Strain_id'> Strain ID</option>
</select>
<select name='fieldsi_op[]'>
<option value='like'>LIKE</option>
<option value='not like'>Not LIKE</option>
<option value='equal'>Equal to</option>
<option value='not_equal'>Not equal to</option>
<option value='='> = </option>
<option value='!='> != </option>
<option value='<='> <= </option>
<option value='>='> >= </option>
<option value='<'> < </option>
<option value='>'> > </option>
</select>
<input type='text' name='keyword[]' id='first_box'>
<input type="button" onclick="addElement()" value="+"> <input type="button" onclick="removeElement()" value="-">
<div id="content" ></div>
<br>
<input type='submit' value='Search'>
</form>
<br>
<br>
<body>
<?php
$dbServerName = "abc";
$dbUsername = "abc";
$dbPassword = "abc";
$dbName = "abc";
// create connection
$conn = new mysqli($dbServerName, $dbUsername, $dbPassword, $dbName);
// check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SHOW COLUMNS FROM $table";
if(isset($_POST['keyword'])){
$key = $_POST['keyword'];
$op = $_POST['op'];
$field = $_POST['fieldsi'];
$field_op = $_POST['fieldsi_op'];
for($i=0;$i<count($key);$i++){
$keyw = $key[$i];
$field_val = $field[$i];
$field_op_val = $field_op[$i];
if($i>0){
$j = $i-1;
$operate = $op[$j];
if($operate != 'not'){
if($field_val == 'all'){
$result = mysqli_query($conn,$sql);
$result1 = mysqli_query("SHOW COLUMNS FROM $table");
echo "$result1";
if (mysqli_num_rows($result) > 0)
{
$i=0;
while ($row = mysqli_fetch_array($result))
{
if($i==0)
{
$fi_name = $row[0];
$display["$fi_name"] = 0;
$qu_mul = $qu_mul.' '.$operate.' '."$fi_name $field_op_val '%$keyw%'";
}
else
{
$fi_name = $row[0];
$display["$fi_name"] = 0;
$qu_mul.=" or "."$fi_name $field_op_val '%$keyw%'";
}
$i++;
}
}
}
else{
$display["$field_val"] = 0;
if(!preg_match('/[like]/i', $field_op_val)){
$qu_mul = $qu_mul.' '.$operate.' '."$field_val $field_op_val $keyw";
}
else if(preg_match('/equal/i', $field_op_val)){
$qu_mul = $qu_mul.' '.$operate.' '."$field_val ='$keyw'";
}
else if(preg_match('/not_equal/i', $field_op_val)){
$qu_mul = $qu_mul.' '.$operate.' '."$field_val !='$keyw'";
}
else{
$qu_mul = $qu_mul.' '.$operate.' '."$field_val $field_op_val '%$keyw%'";
}
}
}
else{
$qu_mul = $qu_mul.' '."and $field_val not like '%$keyw%'";
}
}
else{
if($field_val == 'all'){
$result = mysqli_query("SHOW COLUMNS FROM $table");
if (mysqli_num_rows($result) > 0)
{
$i=0;
while ($row = mysqli_fetch_array($result))
{
if($i==0)
{
$fi_name = $row[0];
$display["$fi_name"] = 0;
if(!preg_match('/[like]/i', $field_op_val)){
$qu = "$fi_name $field_op_val $keyw";
}
else if(preg_match('/equal/i', $field_op_val)){
$qu = "$fi_name ='$keyw'";
}
else if(preg_match('/not_equal/i', $field_op_val)){
$qu = "$fi_name !='$keyw'";
}
else{
$qu = "$fi_name $field_op_val '%$keyw%'";
}
}
else
{
$fi_name = $row[0];
$display["$fi_name"] = 0;
if(!preg_match('/[like]/i', $field_op_val)){
$qu.=" or "."$fi_name $field_op_val $keyw";
}
else if(preg_match('/equal/i', $field_op_val)){
$qu.=" or "."$fi_name ='$keyw'";
}
else if(preg_match('/not_equal/i', $field_op_val)){
$qu.=" or "."$fi_name !='$keyw'";
}
else{
$qu.=" or "."$fi_name $field_op_val '%$keyw%'";
}
}
$i++;
}
}
}
else{
$display["$field_val"] = 0;
if(!preg_match('/[like]/i', $field_op_val)){
$qu = "$field_val $field_op_val $keyw";
}
else if(preg_match('/equal/i', $field_op_val)){
$qu = "$field_val ='$keyw'";
}
else if(preg_match('/not_equal/i', $field_op_val)){
$qu = "$field_val !='$keyw'";
}
else{
$qu = "$field_val $field_op_val '%$keyw%'";
}
}
}
}
$dis="";
$display["Gene_id"] = 0;
#echo "$display";
$display["Gene_name"] = 0;
$display["Gene_product"] = 0;
$display["Function_of_proteins"] = 0;
$display["Protein_id"] = 0;
#$display["Protein_sequence"] = 0;
#$display["Nucleotide_sequence"] = 0;
$display["Protein_length"] = 0;
$display["Localization_of_proteins"] = 0;
$display["Strain_id"] = 0;
$display["Source"] = 0;
foreach($display as $key => $value){
$dis = "$dis"."$key,";
#echo "$dis";
}
$dis = preg_replace("/,$/",'',$dis);
$qu_pre = "select $dis from $table where ";
$sql = "$qu_pre"."$qu"."$qu_mul";
$res = $conn->query("$sql") or die($conn->error);
#echo"<table border=1>";
$res_no = mysqli_num_rows($res);
if($res_no == 0){
"<font color='brown' size='4'><b>No Record Found in CRAB-DB coressponding to your keyword !!!</b></font><br><br><input type='button' value='Go Back' onClick='history.go(-1)'><br><br><br>";
}
else{
$tot_res = mysqli_num_rows($res);
echo "Total number of records = $tot_res";
echo '<br>';
#<!-- back working properly-->
echo "<input type='button' onClick='history.go(-1)' value='Back'><br><br>";
echo '<div style="padding:0px 0px 0px 0px;">';
$query = mysqli_query($conn, $sql);
#echo "<table cellspacing=\"1\" class=\"tablesorter\">";
#echo "<thead><tr>";
if (mysqli_num_rows($query)){
$headerRow = true;
while ($row = mysqli_fetch_assoc($query)){
if ($headerRow){
$headerRow = false;
echo '<table id="example" class="table table-striped table-bordered" style="width:100%">';
echo "<thead>";
echo "<tr>";
foreach (array_keys($row) as $header)
{
echo "<th align = left>$header</a></th>";
}
echo "</tr>";
echo "</thead>";
}
echo '<tbody>';
#echo "<tbody>";
echo "<tr>";
#echo "<td>";
foreach ($row as $value){
echo "<td>$value</td>";
}
echo "</td>";
echo "</tr>";
#echo '</tr>';
echo '</tbody>';
}
}
}
while($row=mysqli_fetch_array($res)){
for($i=0;$i<mysqli_num_fields($res);$i++){
$f_name = mysqli_field_name($res, $i);
$f_val = $row[$f_name];
if($f_name == 'Gene_name'){
print"<td>$f_val</td>";
print "<td><a href='#####.php?Gene_name=$f_val&type=Gene_name' title='Click to See Details' style='text-decoration: none;'>$f_val</a></td>";
}
else if($f_name == 'Gene_id'){
$c_id = $row['Gene_name'];
$res_pub = mysqli_query("select * from $table where Gene_name='$c_id'");
}
print "</th>";
}
}
}
echo "</table>";
echo "<tfoot>";
echo "<tr>";
foreach (array_keys($row) as $header)
{
echo "<th align = left>$header</a></th>";
}
echo "</tr>";
echo "</table>";
echo "</body>";
echo "</html>";
Your code uses relative links. Don't do that. Use Absolute links!
<script src="jquery-3.3.1.js" type="text/javascript"></script>
Depending which folder this script is in, it will look from there, and not the site root.
However, changing it to
<script src="/path/to/jquery-3.3.1.js" type="text/javascript"></script>
Will load it from the site root all the time! In the example I put /path/to/jquery.js, if your index.php is in the public folder, then i usually put js in a js folder, so the link would be /js/jquery-3.3.1.js
Related
I'm working on this code I used Oracle HR database as my database, I'm trying to filter database results based on multiple select, but I keep getting this error:
Warning: oci_execute(): ORA-00933
Warning: oci_fetch_array(): ORA-24374
and no results, my code:
index.php
<html>
<head>
<title>Employees Search</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
function checkinput()
{
if(document.Form2.DEPARTMENT_ID.value=="" && document.Form2.MANAGER_ID.value=="")
{
alert("Please select department or manager!");
return;
}
document.Form2.submit();
}
</script>
</head>
<body>
<form method="get" name="Form2" id="Form2">
<select id="DEPARTMENT_ID" name="DEPARTMENT_ID">
<option value="">DEPARTMENT:</option>
<option value="90">90</option>
<option value="60">60</option>
<option value="100">100</option>
<option value="30">30</option>
</select>
<select id="MANAGER_ID" name="MANAGER_ID" >
<option value="">MANAGER ID:</option>
<option value="100">100</option>
<option value="102">102</option>
<option value="103">103</option>
<option value="108">108</option>
</select>
<input type="button" value=" Search " onclick="checkinput()" />
</form>
<br />
<div id="result">
<?php include "emp.php"; ?>
</div>
</body>
</html>
emp.php
<?php
$conn = oci_connect('hr', ' ', 'My-PC:1521/XE');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
if(isset($_GET['DEPARTMENT_ID'])||isset($_GET['MANAGER_ID'])){
$DEPARTMENT_ID=$_GET['DEPARTMENT_ID'];
$MANAGER_ID=$_GET['MANAGER_ID'];
$sql="SELECT * FROM EMPLOYEES WHERE ";
if($DEPARTMENT_ID != "")
{
$sql = $sql."DEPARTMENT_ID=".$DEPARTMENT_ID;
if($MANAGER_ID != "")
{
$sql = $sql."MANAGER_ID=".$MANAGER_ID;
}
}
else
{
if($MANAGER_ID != "")
{
$sql = $sql."MANAGER_ID=".$MANAGER_ID;
}
}
$stid = oci_parse($conn, $sql);
oci_execute($stid);
echo " <table><tr><th>Employee No.</th><th>First Name</th><th>Last Name</th><th>PHONE NUMBER</th><th>Email</th><th>Job Title</th><th>MANAGER_ID</th><th>DEPARTMENT_ID</th></tr>";
while ($row = oci_fetch_array($stid, OCI_ASSOC )) {
echo "<tr>";
echo "<td>".$row['EMPLOYEE_ID']."</td>";
echo "<td>".$row['FIRST_NAME']."</td>";
echo "<td>".$row['LAST_NAME']."</td>";
echo "<td>".$row['PHONE_NUMBER']."</td>";
echo "<td>".$row['EMAIL']."</td>";
echo "<td>".$row['JOB_ID']."</td>";
echo "<td>".$row['MANAGER_ID']."</td>";
echo "<td>".$row['DEPARTMENT_ID']."</td>";
echo "</tr>";
echo"</table>";
}
}
?>
Everything seems correct expect SQL when Department and manager id is not null.
<?php
$conn = oci_connect('hr', ' ', 'My-PC:1521/XE');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
if(isset($_GET['DEPARTMENT_ID'])||isset($_GET['MANAGER_ID'])){
$DEPARTMENT_ID=$_GET['DEPARTMENT_ID'];
$MANAGER_ID=$_GET['MANAGER_ID'];
$sql="SELECT * FROM EMPLOYEES WHERE ";
if($DEPARTMENT_ID != "")
{
$sql = $sql."DEPARTMENT_ID=".$DEPARTMENT_ID;
if($MANAGER_ID != "")
{
$sql = $sql."AND MANAGER_ID=".$MANAGER_ID;
}
}
else
{
if($MANAGER_ID != "")
{
$sql = $sql."MANAGER_ID=".$MANAGER_ID;
}
}
$stid = oci_parse($conn, $sql);
oci_execute($stid);
echo " <table><tr><th>Employee No.</th><th>First Name</th><th>Last Name</th><th>PHONE NUMBER</th><th>Email</th><th>Job Title</th><th>MANAGER_ID</th><th>DEPARTMENT_ID</th></tr>";
while ($row = oci_fetch_array($stid, OCI_ASSOC )) {
echo "<tr>";
echo "<td>".$row['EMPLOYEE_ID']."</td>";
echo "<td>".$row['FIRST_NAME']."</td>";
echo "<td>".$row['LAST_NAME']."</td>";
echo "<td>".$row['PHONE_NUMBER']."</td>";
echo "<td>".$row['EMAIL']."</td>";
echo "<td>".$row['JOB_ID']."</td>";
echo "<td>".$row['MANAGER_ID']."</td>";
echo "<td>".$row['DEPARTMENT_ID']."</td>";
echo "</tr>";
echo"</table>";
}
}
?>
Changed Line :
$sql = $sql."AND MANAGER_ID=".$MANAGER_ID;
May be reason as SQL failed to parse this query.
As If both are not empty and assumed 10 then you query will be looked like SELECT * FROM EMPLOYEES WHERE DEPARTMENT_ID=10 MANAGER_ID=10; which is not syntactically correct.
I am working on an online shopping cart project, which requires me to be able to add a custom text input field to each item that is added to the shopping cart. However, when I attempt to insert the information for each item in the card into a database, I cannot figure out how to pass the itemtext value into my INSERT statement. How would I go about being able to pass the itemtext value from the initial item list into my database for Orderitems? The itemtext input is on line 170, and I want to pass it into the INSERT statement seen on line 83.
<?php
session_start();
$user = $_SESSION['user'];
if(!isset($user)) {
header("Location:userlogin.php");
}
$cart = $_COOKIE['WSC'];
if(isset($_POST['clear'])) {
$expire = time() -60*60*24*7*365;
setcookie("WSC", $cart, $expire);
header("Location:order.php");
}
if($cart && $_GET['id']) {
$cart .= ',' . $_GET['id'];
$expire = time() +60*60*24*7*365;
setcookie("WSC", $cart, $expire);
header("Location:order.php");
}
if(!$cart && $_GET['id']) {
$cart = $_GET['id'];
$expire = time() +60*60*24*7*365;
setcookie("WSC", $cart, $expire);
header("Location:order.php");
}
if($cart && $_GET['remove_id']) {
$removed_item = $_GET['remove_id'];
$arr = explode(",", $cart);
unset($arr[$removed_item-1]);
$new_cart = implode(",", $arr);
$new_cart = rtrim($new_cart, ",");
$expire = time() +60*60*24*7*365;
setcookie("WSC", $new_cart, $expire);
header("Location:order.php");
}
if(isset($_POST['PlaceOrder'])) {
$email = $user;
$orderdate = date('m/d/Y');
$ordercost = $_POST['ordercost'];
$ordertype = $_POST['ordertype'];
$downcost = $_POST['downcost'];
$cardtype = $_POST['cardtype'];
$cardnumber = $_POST['cardnumber'];
$cardsec = $_POST['cardsec'];
$cardexpdate = $_POST['cardexpdate'];
$orderstatus = "Pending";
if($ordertype=="") {
$ordertypeMsg = "<br><span style='color:red;'>You must enter an order type.</span>";
}
if($cardtype=="") {
$cardtypeMsg = "<br><span style='color:red;'>You must enter a card type.</span>";
}
if($cardnumber=="") {
$cardnumberMsg = "<br><span style='color:red;'>You must enter a card number.</span>";
}
if($cardsec=="") {
$cardsecMsg = "<br><span style='color:red;'>You must enter a security code.</span>";
}
if($cardexpdate=="") {
$cardexpdateMsg = "<br><span style='color:red;'>You must enter an expiration date.</span>";
}
else {
include ('includes/dbc_admin.php');
$sql = "INSERT INTO Orders (email, orderdate, ordercost, ordertype, downcost, cardtype, cardnumber, cardsec, cardexpdate, orderstatus)
VALUES ('$email', '$orderdate', '$ordercost', '$ordertype', '$downcost', '$cardtype', '$cardnumber', '$cardsec', '$cardexpdate', '$orderstatus')";
mysql_query($sql) or trigger_error("WHOA! ".mysql_error());
$sql = "SELECT orderid FROM Orders";
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
while($row=mysql_fetch_assoc($result)) {
$myid = $row[orderid];
}
$itemnumber = 1;
$items = explode(',', $cart);
foreach($items AS $item) {
$sql = "SELECT * FROM Catalog where id = '$item'";
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
while($row=mysql_fetch_assoc($result)) {
$itemtext = $_POST['itemtext'];
$sql= "INSERT INTO OrderItems (orderid, itemnumber, itemid, itemtype, media, itemtext, price)
VALUE ('$myid', '$itemnumber', '$row[itemid]', '$row[itemtype]', '$row[media]', '$itemtext[itemnumber]', '$row[price]')";
mysql_query($sql) or trigger_error("WHOA! ".mysql_error());
}
$itemnumber++;
}
$inserted = "<h2>Thank You!</h2> <h3>Your order has been placed.</h3>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Williams Specialty Company</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function validateForm() {
var ordercost = document.form1.ordercost.value;
var downcost = document.form1.downcost.value;
var ordertype = document.form1.ordertype.value;
var cardtype = document.form1.cardtype.value;
var cardnumber = document.form1.cardnumber.value;
var cardsec = document.form1.cardsec.value;
var cardexpdate = document.form1.cardexpdate.value;
var ordertypeMsg = document.getElementById('ordertypeMsg');
var cardtypeMsg = document.getElementById('cardtypeMsg');
var cardnumberMsg = document.getElementById('cardnumberMsg');
var cardsecMsg = document.getElementById('cardsecMsg');
var cardexpdateMsg = document.getElementById('cardexpdateMsg');
if(ordertype == ""){ordertypeMsg.innerHTML = "You must enter an order type."; return false;}
if(cardtype == ""){cardtypeMsg.innerHTML = "You must enter a card type."; return false;}
if(cardnumber == ""){cardnumberMsg.innerHTML = "You must enter a card number."; return false;}
if(cardsec == ""){cardsecMsg.innerHTML = "You must enter a security code."; return false;}
if(cardexpdate == ""){cardexpdateMsg.innerHTML = "You must enter an expiration date."; return false;}
}
</script>
</head>
<body>
<?php include('includes/header.inc'); ?>
<?php include('includes/nav.inc'); ?>
<div id="wrapper">
<?php include('includes/aside.inc'); ?>
<section>
<h2>My Cart</h2>
<table width="100%">
<tr>
<th>Catalog ID</th>
<th>Item Name</th>
<th>Price</th>
<th>Item Text</th>
<th>Actions</th>
</tr>
<?php
$cart = $_COOKIE['WSC'];
if ($cart) {
$i = 1;
$ordercost;
include('includes/dbc.php');
$items = explode(',', $cart);
foreach($items AS $item) {
$sql = "SELECT * FROM Catalog where id = '$item'";
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
while($row=mysql_fetch_assoc($result)) {
echo '<tr>';
echo '<td align="left">';
echo $row['itemid'];
echo '</td>';
echo '<td align="left">';
echo $row['itemname'];
echo '</td>';
echo '<td align="left">';
echo $row['price'];
$ordercost+=$row['price'];
$downcost = $ordercost / 10;
echo '</td>';
echo '<td align="left">';
echo '<p><input type="text" id= "itemtext" name="itemtext"></p>';
echo '</td>';
echo '<td align="left">';
echo 'Remove From Cart';
echo '</td>';
echo '</tr>';
}
$i++;
}
}
?>
</table><br />
<form method="POST" action="<?php $_SERVER['PHP_SELF'];?>">
<input type="submit" name="clear" value="Empty Shopping Cart">
</form>
<?php if(isset($inserted)) {echo $inserted;} else{ ?>
<form method="post" action="<?php echo $SERVER['PHP_SELF'] ?>" name="form1" onSubmit="return validateForm()">
<p>Total Price: <?php echo $ordercost;?> <input type="hidden" id="ordercost" name="ordercost" value="<?php echo $ordercost;?>"> </p>
<p>Down Cost: <?php echo number_format((float)$downcost, 2, '.', '');?> <input type="hidden" id="downcost" name="downcost" value="<?php echo number_format((float)$downcost, 2, '.', '');?>"> </p>
<p><label>Order Type:</label><br> <input type="text" id="ordertype" name="ordertype">
<?php if(isset($ordertypeMsg)) {echo $ordertypeMsg;} ?>
<br /><span id="ordertypeMsg" style="color:red"></span>
</p>
<p><label>Card Type:</label><br> <input type="text" id="cardtype" name="cardtype">
<?php if(isset($cardtypeMsg)) {echo $cardtypeMsg;} ?>
<br /><span id="cardtypeMsg" style="color:red"></span>
</p>
<p><label>Card Number:</label><br> <input type="text" id="cardnumber" name="cardnumber">
<?php if(isset($cardnumberMsg)) {echo $cardnumberMsg;} ?>
<br /><span id="cardnumberMsg" style="color:red"></span>
</p>
<p><label>Card Security Code:</label><br> <input type="text" id="cardsec" name="cardsec">
<?php if(isset($cardsecMsg)) {echo $cardsecMsg;} ?>
<br /><span id="cardsecMsg" style="color:red"></span>
</p>
<p><label>Card Expiration Date:</label><br> <input type="text" id="cardexpdate" name="cardexpdate">
<?php if(isset($cardexpdateMsg)) {echo $cardexpdateMsg;} ?>
<br /><span id="cardexpdateMsg" style="color:red"></span>
</p>
<p><input type="submit" name="PlaceOrder" value="Place Order"></p>
</form><?php }?>
</section>
</div>
<?php include('includes/footer.inc'); ?>
</body>
</html>
Update: This is your answer: change '$itemtext[itemnumber]' into '$itemtext'
This is going wrong because of the way you use quotes. (not the answer but you might want to think about it ;-) )
$sql = "INSERT INTO Orders (email, orderdate, ordercost, ordertype, downcost, cardtype, cardnumber, cardsec, cardexpdate, orderstatus)
VALUES ('$email', '$orderdate', '$ordercost', '$ordertype', '$downcost', '$cardtype', '$cardnumber', '$cardsec', '$cardexpdate', '$orderstatus')";
You should not use '$email' but -for example- ...VALUES ('".$email."',...
Learn more about this here: What is the difference between single-quoted and double-quoted strings in PHP?
On another note, your code is not safe. Please use: http://php.net/manual/en/function.mysql-real-escape-string.php
Example:
...VALUES ('".mysql_real_escape_string($email)."',...
I have written a page that displays a load of data from MySQL database and all works perfect EXCEPT that when i click the Home link (the title of the page) it logs out and i need to log back in, im probably missing something stupid or not doing something i need, code below
<?php
session_start();
?><title>Vend365 Monitor (Beta test)</title>
<h1><u>Vend 365 online monitor (Beta test)<p></p></u></h3>
<?php
require_once ("V365Connect.php");
//Following if 'update' is clicked
if (isset($_POST['lastseen'])){?><p>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 1px;
text-align: left;
}
</style>
<h1>Vend 'Last Seen' times: Page loaded at <?php echo date("d/m/Y G:i:s"); ?></h1>
<?php
$result1 = mysql_query("SELECT distinct customer FROM vends order by customer") or die(mysql_error());
while($row = mysql_fetch_assoc($result1))
{ echo '<table><th>';
?><font size = "5">Customer - '<?php echo $row[customer];?>'</font><?php
echo '</th>';
$result2 = mysql_query("SELECT * FROM vends where customer ='".$row[customer]."'") or die(mysql_error());
while($row1 = mysql_fetch_assoc($result2))
{
echo '<tr><td>';
?>Machine <b>'<?php echo $row1[machine];?>'</b> last seen online at <b>'<?php echo $row1[lastseen];?>'</b> running version <b>'<?php echo $row1[myversion];?>'</b><?php
$today = date("d/m/Y G:i:s");
$lastseentime = $row1[lastseen];
$diff = $today-$lastseentime;
if ($diff == "1"){
?><b> <font color = "red"> -- Last seen online yesterday</font></b> <?php ;}
if ($diff > "1"){
?> <b><font color = "red"> -- Last seen online BEFORE yesterday</font></b> <?php ;}
echo '</td></tr><p>' ;
}
}?></table>
<?php
}else{
if (isset($_POST['update'])){
if ($_POST['checkbox']=='checked'){
$isalive = 1;
} else {
$isalive = 0;
}
if ($_POST['checkbox1']=='checked'){
$hb800 = 1;
} else {
$hb800 = 0;
}
if ($_POST['checkbox2']=='checked'){
$hb1100 = 1;
} else {
$hb1100 = 0;
}
if ($_POST['checkbox3']=='checked'){
$hb1400 = 1;
} else {
$hb1400 = 0;
}
if ($_POST['checkbox4']=='checked'){
$hb1700 = 1;
} else {
$hb1700 = 0;
}
if ($_POST['checkbox5']=='checked'){
$gcmreboot = 1;
} else {
$gcmreboot = 0;
}
if ($_POST['checkbox6']=='checked'){
$emailreboot = 1;
} else {
$emailreboot = 0;
}
if ($_POST['checkbox7']=='checked'){
$hbgcm = 1;
} else {
$hbgcm = 0;
}
if ($_POST['checkbox8']=='checked'){
$hbemail = 1;
} else {
$hbemail = 0;
}
if ($_POST['checkbox9']=='checked'){
$edigcm = 1;
} else {
$edigcm = 0;
}
if ($_POST['checkbox10']=='checked'){
$ediemail = 1;
} else {
$ediemail = 0;
}
if ($_POST['checkbox11']=='checked'){
$reportgcm = 1;
} else {
$reportgcm = 0;
}
if ($_POST['checkbox12']=='checked'){
$reportemail = 1;
} else {
$reportemail = 0;
}
if ($_POST['checkbox13']=='checked'){
$pingmailgcm = 1;
} else {
$pingmailgcm = 0;
}
if ($_POST['checkbox14']=='checked'){
$pingmailemail = 1;
} else {
$pingmailemail = 0;
}
if ($_POST['checkbox15']=='checked'){
$internetgcm = 1;
} else {
$internetgcm = 0;
}
if ($_POST['checkbox16']=='checked'){
$internetemail= 1;
} else {
$internetemail = 0;
}
if ($_POST['checkbox17']=='checked'){
$sqlgcm = 1;
} else {
$sqlgcm = 0;
}
if ($_POST['checkbox18']=='checked'){
$sqlemail = 1;
} else {
$sqlemail = 0;
}
if ($_POST['checkbox19']=='checked'){
$backupgcm = 1;
} else {
$backupgcm = 0;
}
if ($_POST['checkbox20']=='checked'){
$backupemail = 1;
} else {
$backupemail = 0;
}
$sqlupdate = "update vends set isalive='".$isalive."',customer='".$_POST['customer']."',machine='".$_POST['machine']."',mailserver='".$_POST['smtp']."',emails='".$_POST['emails']."',gcm='".$_POST['gcm']."',hb800='".$hb800."',hb1100='".$hb1100."',hb1400='".$hb1400."',hb1700='".$hb1700."',sqlserver='".$_POST['sqlserver']."',sqlport='".$_POST['sqlport']."',sqlinstance='".$_POST['sqlinstance']."',sqldatabase='".$_POST['sqldatabase']."',sqlname='".$_POST['sqlname']."',sqlpassword='".$_POST['sqlpassword']."',rebootgcm='".$gcmreboot."',rebootemail='".$emailreboot."',hbgcm='".$hbgcm."',hbemail='".$hbemail."',edigcm='".$edigcm."',ediemail='".$ediemail."',reportgcm='".$reportgcm."',reportemail='".$reportemail."',mailpinggcm='".$pingmailgcm."',mailpingemail='".$pingmailemail."',internetgcm='".$internetgcm."',internetemail='".$internetemail."',sqlgcm='".$sqlgcm."',sqlemail='".$sqlemail."',backupgcm='".$backupgcm."',backupemail='".$backupemail."',lastseen='".$lastseen."' where mac='".$_SESSION['mac']."'";
mysql_query($sqlupdate) or die(mysql_error());?><h1>
--->Customer - <font color = blue><?php echo $_SESSION['customer'];?></font>
<br />
--->Machine - <font color = blue><?php echo $_SESSION['machine'];?></font>
<p>
<?php
echo "Request sent";
}
else
{
//First load screen to select customer when correct details are entered
if (!isset($_POST['update'])){
if (!isset($_POST['customer'])){
if (!isset($_POST['machine'])){
if (isset($_POST['submit'])){
$result = mysql_query("SELECT * FROM users where user='".$_POST['user']."' and pass='".$_POST['pass']."'") or die(mysql_error());
$count = mysql_num_rows($result);
if ($count == 1){
?><p><p> <table style="border:1px solid black;"><tr><td><h1>Welcome '<?php echo $_POST['user'];?>'</td></tr></table><?php
$_SESSION['customer'];
$_SESSION['machine'];
$_SESSION['mac'];
if (!isset($_POST['customer'])) {
if (!isset($_POST['machine'])) {
echo "<h1><form action ='' method='post'>";
echo "Please Select Your Customer<br />";
$result1 = mysql_query("SELECT distinct customer FROM vends order by customer") or die(mysql_error());
echo "<select name='customer'>";
while($row = mysql_fetch_assoc($result1))
{
echo "<option value = '".$row[customer]."'>".$row[customer]."</option>";
}
echo "</select>";
echo "<input type='submit' value='Go'>";
echo "</form>";
echo "";
echo "Show all 'Last Seen' times";
?>
<form method='post'>
<input type='submit' value='Show Last Seen Status' name ='lastseen' />
</form>
<?php
}
}}else {
// If wrong details entered
echo "Sorry, wrong username or password, please go back and try again";
}
} else {
// Following is first time load screen
?>
<!DOCTYPE HTML> <html>
<head>
<link rel="stylesheet" type="text/css" href="style-sign.css">
</head><h1>
<title>Vend 365 Monitor</title>
<body id="body-color">
<div id="Sign-In">
<fieldset style="width:30%">
<legend>LOG-IN HERE</legend>
<form method="POST"> User <br><input type="text" style="font-size: 30px;" name="user" size="20"><br> Password <br><input type="password" style="font-size: 30px;" name="pass" size="20"><br>
<input id="button" type="submit" style="font-size: 30px; "name="submit" value="Log-In"> </form> </fieldset>
</div>
</body>
</html>
<?php
}}}
} else {
}
?>
<?php
// Select a vending machine
if (!isset($_POST['submit'])){
if (isset($_POST['customer'])) {
$example = $_POST['customer'];
$_SESSION['customer'] = $example;
$result2 = mysql_query("SELECT * FROM vends where customer='".$example."'") or die(mysql_error());
?><h1>
<font color = black>--->Customer - <font color = blue><?php
echo $_SESSION['customer'];?><p></font></font><?php
echo "<form action ='' method='post'>";
echo "Please Select Your Machine<br />";
echo "<select name='machine'>";
while($row = mysql_fetch_assoc($result2))
{
echo "<option value = '".$row[machine]."'>".$row[machine]."</option>";
}
echo "</select>";
echo "<input type='submit' value='Go'>";
echo "</form>";
}}
// show all customer/machine info
if (isset($_POST['machine'])) {
$example1 = $_POST['machine'];
$_SESSION['machine'] = $example1;?>
<h1><font color = black>--->Customer - <font color = blue><?php
echo $_SESSION['customer'];?><br /></font></font><br /><font color = black>--->Machine - <font color = blue><?php
echo $_SESSION['machine']; ?><p><?php
$result3 = mysql_query("SELECT * FROM vends where customer='".$_SESSION['customer']."' and machine ='".$_SESSION['machine']."'") or die(mysql_error());
while ($rows = mysql_fetch_assoc($result3))
{
$tag1 = $rows['hb800'];
$checkedstatus1 = '';
if($tag1 == '1')
{
$checkedstatus1 = 'checked';
} else {
$checkedstatus1 = 'unchecked';
}?><font color = black><form method='post'>
0800 Heartbeat check - <input type='checkbox' value='checked' name='checkbox1' <?php echo $checkedstatus1; ?> />
<br /><?php
$tag2 = $rows['hb1100'];
$checkedstatus2 = '';
if($tag2 == '1')
{
$checkedstatus2 = 'checked';
} else {
$checkedstatus2 = 'unchecked';
}?>
1100 Heartbeat check- <input type='checkbox' value='checked' name='checkbox2' <?php echo $checkedstatus2; ?> />
<br />
<?php $tag3 = $rows['hb1400'];
$checkedstatus3 = '';
if($tag3 == '1')
{
$checkedstatus3 = 'checked';
} else {
$checkedstatus3 = 'unchecked';
}?>
1400 Heartbeat check - <input type='checkbox' value='checked' name='checkbox3' <?php echo $checkedstatus3; ?> />
<br />
<?php
$tag4 = $rows['hb1700'];
$checkedstatus4 = '';
if($tag4 == '1')
{
$checkedstatus4 = 'checked';
} else {
$checkedstatus4 = 'unchecked';
}?>
1700 Heartbeat check - <input type='checkbox' value='checked' name='checkbox4' <?php echo $checkedstatus4; ?> /><br />
<?php
$tag5 = $rows['rebootgcm'];
$checkedstatus5 = '';
if($tag5 == '1')
{
$checkedstatus5 = 'checked';
} else {
$checkedstatus5 = 'unchecked';
}?>
Send GCM when rebooted - <input type='checkbox' value='checked' name='checkbox5' <?php echo $checkedstatus5; ?> /><br />
<?php
$tag6 = $rows['rebootemail'];
$checkedstatus6 = '';
if($tag6 == '1')
{
$checkedstatus6 = 'checked';
} else {
$checkedstatus6 = 'unchecked';
}?>
Send email when rebooted - <input type='checkbox' value='checked' name='checkbox6' <?php echo $checkedstatus6; ?> /><br />
<?php
$tag7 = $rows['hbgcm'];
$checkedstatus7 = '';
if($tag7 == '1')
{
$checkedstatus7 = 'checked';
} else {
$checkedstatus7 = 'unchecked';
}?>
Heartbeat check GCM - <input type='checkbox' value='checked' name='checkbox7' <?php echo $checkedstatus7; ?> /><br />
<?php
$tag8 = $rows['hbemail'];
$checkedstatus8 = '';
if($tag8 == '1')
{
$checkedstatus8 = 'checked';
} else {
$checkedstatus8 = 'unchecked';
}?>
Heartbeat check Email - <input type='checkbox' value='checked' name='checkbox8' <?php echo $checkedstatus8; ?> /><br />
<?php
$tag9 = $rows['edigcm'];
$checkedstatus9 = '';
if($tag9 == '1')
{
$checkedstatus9 = 'checked';
} else {
$checkedstatus9 = 'unchecked';
}?>
EDI fail check GCM - <input type='checkbox' value='checked' name='checkbox9' <?php echo $checkedstatus9; ?> /><br />
<?php
$tag10 = $rows['ediemail'];
$checkedstatus10 = '';
if($tag10 == '1')
{
$checkedstatus10 = 'checked';
} else {
$checkedstatus10 = 'unchecked';
}?>
EDI fail check Email - <input type='checkbox' value='checked' name='checkbox10' <?php echo $checkedstatus10; ?> /><br />
<?php
$tag11 = $rows['reportgcm'];
$checkedstatus11 = '';
if($tag11 == '1')
{
$checkedstatus11 = 'checked';
} else {
$checkedstatus11 = 'unchecked';
}?>
Report fail GCM - <input type='checkbox' value='checked' name='checkbox11' <?php echo $checkedstatus11; ?> /><br />
<?php
$tag12 = $rows['reportemail'];
$checkedstatus12 = '';
if($tag12 == '1')
{
$checkedstatus12 = 'checked';
} else {
$checkedstatus12 = 'unchecked';
}?>
Report fail Email - <input type='checkbox' value='checked' name='checkbox12' <?php echo $checkedstatus12; ?> /><br />
<?php
$gcm = $rows[gcm];
$tag13 = $rows['mailpinggcm'];
$checkedstatus13 = '';
if($tag13 == '1')
{
$checkedstatus13 = 'checked';
} else {
$checkedstatus13 = 'unchecked';
}?>
Ping email server GCM - <input type='checkbox' value='checked' name='checkbox13' <?php echo $checkedstatus13; ?> /><br />
<?php
$tag14 = $rows['mailpingemail'];
$checkedstatus14 = '';
if($tag14 == '1')
{
$checkedstatus14 = 'checked';
} else {
$checkedstatus14 = 'unchecked';
}?>
Ping email server Email - <input type='checkbox' value='checked' name='checkbox14' <?php echo $checkedstatus14; ?> /><br />
<?php
$tag15 = $rows['internetgcm'];
$checkedstatus15 = '';
if($tag15 == '1')
{
$checkedstatus15 = 'checked';
} else {
$checkedstatus15 = 'unchecked';
}?>
Ping internet fail GCM - <input type='checkbox' value='checked' name='checkbox15' <?php echo $checkedstatus15; ?> /><br />
<?php
$tag16 = $rows['internetemail'];
$checkedstatus16 = '';
if($tag16 == '1')
{
$checkedstatus16 = 'checked';
} else {
$checkedstatus16 = 'unchecked';
}?>
Ping internet fail email - <input type='checkbox' value='checked' name='checkbox16' <?php echo $checkedstatus16; ?> /><br />
<?php
$tag17 = $rows['sqlgcm'];
$checkedstatus17 = '';
if($tag17 == '1')
{
$checkedstatus17 = 'checked';
} else {
$checkedstatus17 = 'unchecked';
}?>
Failed SQL ping GCM - <input type='checkbox' value='checked' name='checkbox17' <?php echo $checkedstatus17; ?> /><br />
<?php
$tag18 = $rows['sqlemail'];
$checkedstatus18 = '';
if($tag18 == '1')
{
$checkedstatus18 = 'checked';
} else {
$checkedstatus18 = 'unchecked';
}?>
Failed SQL ping email - <input type='checkbox' value='checked' name='checkbox18' <?php echo $checkedstatus18; ?> /><br />
<?php
$tag19 = $rows['backupgcm'];
$checkedstatus19 = '';
if($tag19 == '1')
{
$checkedstatus19 = 'checked';
} else {
$checkedstatus19 = 'unchecked';
}?>
Backup fail GCM - <input type='checkbox' value='checked' name='checkbox19' <?php echo $checkedstatus19; ?> /><br />
<?php
$tag20 = $rows['backupemail'];
$checkedstatus20 = '';
if($tag20 == '1')
{
$checkedstatus20 = 'checked';
} else {
$checkedstatus20 = 'unchecked';
}?>
Backp fail email - <input type='checkbox' value='checked' name='checkbox20' <?php echo $checkedstatus20; ?> /><br />
<u><b><p>Details</b></u><p>
<?php $_SESSION['mac'] = $rows[mac]; ?>
Mac address - '<?php echo $_SESSION['mac']; ?>'<br />
Customer name - '<?php echo $rows[customer]; ?>'<br />
Machine name - '<?php echo $rows[machine]; ?>'<br />
Current version - '<?php echo $rows[myversion]; ?>'<br />
GCM app code - <input type='text' value='<?php echo $gcm; ?>' size=150 rows=4 name='gcm' />......<br />
SMTP server - '<?php echo $rows[mailserver]; ?>'<br />
Email addresses (seperate by commas) - '<?php echo $rows[emails]; ?>'<br /><p>
<u><b>SQL Credentials</b></u><p>
SQL server - '<?php echo $rows[sqlserver]; ?>'<br />
SQL Port - '<?php echo $rows[sqlport]; ?>'<br />
SQL Instance - '<?php echo $rows[sqlinstance] ?>'<br />
SQL Database - '<?php echo $rows[sqldatabase]; ?>'<br />
SQL User name - '<?php echo $rows[sqlname]; ?>'<br />
SQL Password - '<?php echo $rows[sqlpassword]; ?>' <br /><p>
<p>
<u><b>Alive status</u></b><p>
Last seen online - '<?php echo $rows[lastseen]; ?>'<br />
<?php
$tag = $rows['isalive'];
$checkedstatus = '';
if($tag == '1')
{
$checkedstatus = 'checked';
} else {
$checkedstatus = 'unchecked';
}?>
Request 'IsAlive' status - <input type='checkbox' value='checked' name='checkbox' <?php echo $checkedstatus; ?> /> - This will send a GCM and Email if alive.<p>
<input type='submit' value='Update account details' name ='update' /><p>
</form><p>
<?php
}}}}
?>
The idea of the following code is that the user will search based on maintenance operation No, operation type, the member who performs the operation, or the employee whose PC needs maintenance. When the user selects, for example, the operation type, a drop-down menu will show up and then he selects the type. After that a table of maintenance information will show up. For example, the user selects the type Printing. The table will show the following information:
Operation No, Member Name, Employee Name, Maintenance Type
1001, Adem, John, Printing
1003, George, Smith, Printing
1010, William, John, Printing
The problem that I am facing is when the user selects search by operation no, for example, and he selects the operation no is 1001, the rest of the rows (1003 and 1010 that were shown based on the previous search) are still shown up (they must be hidden because they do not match with the search type).
The code is
<script>
function check() {
var dropdown = document.getElementById("OpType");
var current_value = dropdown.options[dropdown.selectedIndex].value;
if (current_value == "OpNo") {
document.getElementById("operationno").style.display = "block";
document.getElementById("MainType").style.display = "none";
document.getElementById("MemName").style.display = "none";
document.getElementById("EmpName").style.display = "none";
}
else if (current_value == "OpTyp") {
document.getElementById("MainType").style.display = "block";
document.getElementById("MemName").style.display = "none";
document.getElementById("EmpName").style.display = "none";
document.getElementById("operationno").style.display = "none";
}
else if (current_value == "OpMem") {
document.getElementById("MemName").style.display = "block";
document.getElementById("operationno").style.display = "none";
document.getElementById("MainType").style.display = "none";
document.getElementById("EmpName").style.display = "none";
}
else if (current_value == "OpEmp"){
document.getElementById("MemName").style.display = "none";
document.getElementById("operationno").style.display = "none";
document.getElementById("MainType").style.display = "none";
document.getElementById("EmpName").style.display = "block";
}
else if (current_value == "blank") {
document.getElementById("MainType").style.display = "none";
document.getElementById("MemName").style.display = "none";
document.getElementById("EmpName").style.display = "none";
document.getElementById("operationno").style.display = "none";
}
}
</script>
<form name="f1" action="FollowOperations.php" method="post">
<select id="OpType" onChange="check();">
<option value="blank">Choose</option>
<option value="OpNo">Operation No</option>
<option value="OpTyp">Operation Type</option>
<option value="OpMem">Maintenance Member</option>
<option value="OpEmp">Employee</option>
</select><br>
<input class="tb10" type="text" id="operationno" size="4" style="text-align: center" style="display: none">
<select id="MainType" style="display: none">
<option value="blank">Choose</option>
<option value="printing">Printing</option>
<option value="maintenance">PC Maintenance</option>
<option value="internet">Internet Problem</option>
<option value="software">Software</option>
<option value="email">Email Problem</option>
<option value="usbcd">USB/CD Problem</option>
</select>
<select id="MemName" style="display: none">
<option value="blank">Choose</option>
<option value="john">John</option>
<option value="hen">Hen</option>
</select>
<select id="EmpName" style="display: none">
<option value="blank">Choose</option>
<option value="smith">Smith</option>
<option value="will">William</option>
<option value="Gor">George</option>
</select>
<input type="submit" value="Submit" class="button" />
</form>
<?php
if (isset($_POST['formsubmitted']))
{
$operationno = $_POST['ono'];
echo "<table id='tfhover' class='tftable' border='1' align='center'>";
echo "<tr align='center'><th></th><th align='center'>Type</th><th>Employee</th><th align='center'>Member</th><th align='center'>Operation No</th></tr>";
$query_retrieve_maintenance = "Select * from Maintenance where ID = '$operationno'";
$result_retrieve_maintenance = mysqli_query($dbh, $query_retrieve_maintenance);
while($row1 = mysqli_fetch_array($result_retrieve_maintenance))
{
echo "<tr>";
echo "<td><a href='PastOperationsDet.php?operation_number=".$row1['ID']."' target='_blank'>Show</a></td> ";
echo "<td>".$row1['Type']."</td> ";
echo "<td>".$row1['MemName']."</td> ";
echo "<td>".$row1['EmpName']."</td> ";
echo "<td>".$row1['ID']."</td> ";
}
$MainType = $_POST['mt'];
$query_retrieve_by_type = "Select * from Maintenance where Type = '$MainType'";
$result_retrieve_by_type = mysqli_query($dbh, $query_retrieve_by_type);
while($row1 = mysqli_fetch_array($result_retrieve_by_type))
{
echo "<tr>";
echo "<td><a href='PastOperationsDet.php?operation_number=".$row1['ID']."' target='_blank'>Show</a></td> ";
echo "<td>".$row1['Type']."</td> ";
echo "<td>".$row1['MemName']."</td> ";
echo "<td>".$row1['EmpName']."</td> ";
echo "<td>".$row1['ID']."</td> ";
}
$MemName = $_POST['mn'];
$query_retrieve_by_member = "Select ID from Member where Name = '$MemName'";
$result_retrieve_by_member = mysqli_query($dbh, $query_retrieve_by_member);
$membID = mysqli_fetch_row($result_retrieve_by_member);
$memb_id = $membID[0];
$query_retrieve_by_membername = "Select * from Maintenance where MemberID = '$memb_id'";
$result_retrieve_by_membername = mysqli_query($dbh, $query_retrieve_by_membername);
while($row1 = mysqli_fetch_array($result_retrieve_by_membername))
{
echo "<tr>";
echo "<td><a href='PastOperationsDet.php?operation_number=".$row1['ID']."' target='_blank'>Show</a></td> ";
echo "<td>".$row1['Type']."</td> ";
echo "<td>".$memb_id."</td> ";
echo "<td>".$row1['EmpName']."</td> ";
echo "<td>".$row1['ID']."</td> ";
}
$EmpName = $_POST['me'];
$query_retrieve_by_employee = "Select ID from Employee where Name = '$EmpName'";
$result_retrieve_by_employee = mysqli_query($dbh, $query_retrieve_by_employee);
$emplID = mysqli_fetch_row($result_retrieve_by_employee);
$empl_id = $emplID[0];
$query_retrieve_by_emplid = "Select * from Maintenance where EmployeeID = '$empl_id'";
$result_retrieve_by_emplid = mysqli_query($dbh, $query_retrieve_by_emplid);
while($row1 = mysqli_fetch_array($result_retrieve_by_emplid))
{
echo "<tr>";
echo "<td><a href='PastOperationsDet.php?operation_number=".$row1['ID']."' target='_blank'>Show</a></td> ";
echo "<td>".$row1['Type']."</td> ";
echo "<td>".$row1['MemName']."</td> ";
echo "<td>".$empl_id."</td> ";
echo "<td>".$row1['ID']."</td> ";
}
echo "</table>";
}
?>
Nass,
I took the liberty to make a fiddle for this case.
Take a look at it and ask if you don't understand it.
i hope it helps.
Kind regards, Alex
In this link, http://jsfiddle.net/QthB6/10/, it's set up in a clean way, like;
function blockify () { // for style.display = "block"
}
function unblockify () { // for style.display = "none"
}
At first try to simplify your code
function check() {
var dropdown = document.getElementById("OpType");
var current_value = dropdown.options[dropdown.selectedIndex].value;
var aIds = ['operationno', 'MainType', 'MemName', 'EmpName'];
for(var i = aIds.length; i>=0; i-- ) {
var ob = document.getElementById(aIds[i]);
if( current_value == aIds[i] ) {
ob.style.display = "block"
}
else {
ob.style.display = "none"
}
}
....
<select id="OpType" onChange="check();">
<option value="blank">Choose</option>
<option value="operationno">Operation No</option>
<option value="MainType">Operation Type</option>
<option value="MemName">Maintenance Member</option>
<option value="EmpName">Employee</option>
</select>
....
Then append "name" atrtribute to your input's and select's field.
And then try to print_r your $_POST array to see it values.
I'm working on news archive page for my website, search over archive is done with start date, end date and news category as search parameters. Form values are stored in $_SESSION var, and then they are passed around as an array for pagination and other purposes.
My question would be how to prevent displaying search results on main archive search page if user for some reason goes again to it to make a new search.
here's the code
<?php
session_start();
if (isset($_POST['submit'])) {
//get data from the form
$archFld_1 = $_POST['archiveFld1'];
$archFld_2 = $_POST['archiveFld2'];
$archFld_3 = $_POST['archiveFld3'];
//just some check on fields
if (strlen($archFld_1) > 10) { $archFld_1 = ""; }
if (strlen($archFld_2) > 10) { $archFld_2 = ""; }
//save them as a array and store to session var
$_archValues = array($archFld_3, $archFld_1, $archFld_2);
$_SESSION['storeValues'] = $_archValues;
}
if (isset($_SESSION['storeValues'])) {
//check params for search
//set cat for query
if ($_SESSION['storeValues'][0] > 0) { $valCat = "AND newsCat=". $_SESSION['storeValues'][0] ." "; } else { $valCat = ""; }
//set date for query
if(($_SESSION['storeValues'][1] != "" ) && ($_SESSION['storeValues'][2] == "")) {
$DateStart = $_SESSION['storeValues'][1];
$valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') >= STR_TO_DATE('$DateStart', '%d-%m-%Y') ";
}
if(($_SESSION['storeValues'][2] != "") && ($_SESSION['storeValues'][1]=="")) {
$DateEnd = $_SESSION['storeValues'][2];
$valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') <= STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
}
if(($_SESSION['storeValues'][1]!="") && ($_SESSION['storeValues'][2] != "")) {
$DateStart = $_SESSION['storeValues'][1];
$DateEnd = $_SESSION['storeValues'][2];
$valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') BETWEEN STR_TO_DATE('$DateStart', '%d-%m-%Y') AND STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
}
//query string and stire it to session
$archQuery_string = $valCat.$valDate;
$_SESSION['storeQuery'] = $archQuery_string;
}
//pagination start
$page = $_GET['id'];
$perPage = 10;
$result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION["storeQuery"] ."ORDER BY newsId DESC");
$totalPages = mysql_num_rows($result);
if(!$page)
$page = 1;
$start = ($page - 1)*$perPage;
?>
<div id="sps_middle">
<div class="sps_cnt">
<div id="sps_middle_ly1">
<div class="sps_cnt_small">
<div class="sps_page_title"><h3><?php echo $wb_lng['txtArchiveTitle']; ?></h3></div>
<div class="sps_pages_cnt" style="padding-top: 10px; float: left; margin-bottom: 15px;">
<div class="sps_middle_col01">
<div style="float: left;">
<p>
<?php echo $wb_lng['txtArchiveInfo']; ?>
</p>
<form action="<?php $PHP_SELF; ?>" method="post" name="archiveForm" class="archiveForm">
<ul>
<li>
<input name="archiveFld1" type="text" id="archiveFld1" value="<?php echo $wb_lng['txtArhivaFld_01']; ?>" />
<input name="archiveFld2" type="text" id="archiveFld2" value="<?php echo $wb_lng['txtArhivaFld_02']; ?>" />
<select name="archiveFld3">
<option value="0"><?php echo $wb_lng['txtArhivaFld_07']; ?></option>
<option value="0" ><?php echo $wb_lng['txtArhivaFld_06']; ?></option>
<option value="1"><?php echo $wb_lng['txtArhivaFld_03']; ?></option>
<option value="2"><?php echo $wb_lng['txtArhivaFld_04']; ?></option>
<option value="3"><?php echo $wb_lng['txtArhivaFld_05']; ?></option>
</select>
</li>
<li style="float: right;">
<input name="reset" type="reset" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormReset']; ?>"/>
<input name="submit" type="submit" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormSend']; ?>"/>
</li>
</ul>
</form>
</div>
<hr />
<?php
if (#HERE GOES SOME CODE TO PERFORM THE CHECK!!!#) {
//perform db query
$result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION['storeQuery'] ."ORDER BY newsId DESC LIMIT $start, $perPage");
//count rows
$totalnews = mysql_num_rows($result);
$count = 1;
if($totalnews == 0) {
//no results, say to the user
echo "\t\t\t<div class=\"cil_news_text_big\">\n\t\t\t\t".$wb_lng['txtArchiveNoEntries']."\n\t\t\t</div>\n";
} else {
//we have results, yeeeeeeeeey
while($ROWnews = mysql_fetch_object($result)){
//set link extensions by the news cat
switch ($ROWnews->newsCat) {
case 1:
$newsCat_link = "news";
break;
case 2:
$newsCat_link = "statements";
break;
case 3:
$newsCat_link = "events";
break;
}
//text summary
if (strlen($ROWnews->newsShort) > 0 ) {$newsShortTxt = strip_tags($ROWnews->newsShort);
if ($lang_id==2) { $newsShortTxt = wbTranslit($newsShortTxt); }
} else {
$newsShortTxt = strip_tags($ROWnews->newsFull);
if ($lang_id==2) { $newsShortTxt = wbTranslit($newsShortTxt); }
}
$newsShortTxt = wbShorTxt($newsShortTxt, 210, "... <a title=\"".$wb_lng['txtShowMore']."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$wb_lng['txtShowMore']."...</a>");
//show news
echo "\t\t<div class=\"sps_news_list\">\n";
echo "\t\t<div class=\"sps_news_l\">\n";
echo "\t\t\t<img alt=\"\" src=\"http://".$_SERVER['HTTP_HOST']."/content/images/news/_thumb/".$ROWnews->newsImageThumb."\" />\n";
echo "\t\t</div>";
echo "\t\t<div class=\"sps_news_r\">\n";
//transliterate title
if ($lang_id==2) { $newsTitle = wbTranslit($ROWnews->newsTitle); } else { $newsTitle = $ROWnews->newsTitle; }
echo "\t\t\t<div class=\"sps_news_title\">\n\t\t\t\t<a title=\"".$newsTitle."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$newsTitle."</a>\n\t\t\t</div>\n";
echo "\t\t\t<div class=\"sps_news_date\">\n\t\t\t\t".$ROWnews->newsDate."\n\t\t\t</div>\n";
echo "\t\t\t<div class=\"sps_news_text_sh\">\n\t\t\t\t".$newsShortTxt."\n\t\t\t</div>\n";
echo "\t\t</div>";
echo "\t\t</div>";
//show <hr /> based on $count
if($totalnews != $count) { echo "\t\t\t<hr />\n"; }
$count++;
}
}
//pagination check
if($totalPages>$perPage) {
?>
<hr />
<div class="sps_pagginate">
<?PHP wbPageTurnFront($PHP_SELF."/".$lang_link."/archive/", $totalPages, $page, $perPage); ?>
</div>
<?php
}
}
?>
Any ideas?
Tnx :)
If user goes to make it a new search then you can clear the session at that time.
unset($_SESSION['storeValues']);