Not able to print a table in html using Javascript - javascript

I am simply trying to print a table using javascript but for whatever reason I cannot get it to work. Any advice would be appricated
Here is my code:
<?php
include 'connect.php';
function echoActiveClassIfRequestMatches($requestUri)
{
$current_file_name = basename($_SERVER['REQUEST_URI'], ".php");
if ($current_file_name == $requestUri)
echo 'class="active"';
}
if(isset($_POST['add']))
{
header("Location: add_client.php");
die();
}
if(isset($_POST['delete']))
{
$DBH = connectDB();
$trimmed_id = substr($_POST['delete'], 14) ;
$DBH->exec('DELETE FROM clients where client_ID=' . $trimmed_id);
}
if(isset($_POST['modify']))
{
$trimmed_id = substr($_POST['modify'], 13);
header('Location: modify_client.php?client='.$trimmed_id);
die();
}
if(isset($_POST['logout']))
{
header("Location: index.php");
die();
}
if(isset($_POST['Print']))
{
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Windows and Doors</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script type="text"/javascript">
function printPage() {
{
var DocumentContainer = document.getElementById('printTable');
var WindowObject = window.open('', "TrackHistoryData",
"width=740,height=325,top=200,left=250,toolbars=no,scrollbars=yes,status=no,resizable=no");
WindowObject.document.writeln(DocumentContainer.innerHTML);
WindowObject.document.close();
WindowObject.focus();
WindowObject.print();
WindowObject.close();
}
</script>
<body background="windows.jpg" >
<nav class="navbar navbar-inverse navbar-static-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Windows and Doors</a>
</div>
<div>
<ul class="nav navbar-nav navbar-right">
<li <?=echoActiveClassIfRequestMatches("homepage")?>>
Home</li>
<li <?=echoActiveClassIfRequestMatches("clientspage")?>>
Clients</li>
<li <?=echoActiveClassIfRequestMatches("contact")?>>
Contact</li>
<li <?=echoActiveClassIfRequestMatches("settings")?>>
Settings</li>
<li <?=echoActiveClassIfRequestMatches("reminder")?>>
Reminder</li>
</ul>
</div>
<form class="navbar-form navbar-left" role="search" method="post">
<div class="form-group">
<input type="text" name="searchvalue" class="form-control" placeholder="Search">
</div>
<button type="search" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
</form>
</div>
<form class="btn pull-right" name="form1" method="post" action="" >
<input name="logout" type="submit" value="Logout">
</form>
</nav>
<div class="container" id = "printTable">
<?php
require_once 'connect.php';
$DBH = connectDB();
session_start();
$STH = $DBH->prepare('SELECT * FROM clients');
$STH->execute();
?>
<table border= "5px" style="width:1250px" height=200 id="printTable1">
<th bgcolor="lightgrey"> Select </th>
<th bgcolor="lightgrey"> ID </th>
<th bgcolor="lightgrey"> First Name </th>
<th bgcolor="lightgrey"> Last Name </th>
<th bgcolor="lightgrey"> Address </th>
<th bgcolor="lightgrey"> Manufacturer </th>
<th bgcolor="lightgrey"> Gender </th>
<th bgcolor="lightgrey"> Notes </th>
<th bgcolor="lightgrey"> Delete or modify record</th>
<?php
if(isset($_POST['searchvalue']))
{
$searchvalue = $_POST['searchvalue'];
$STH = $DBH->prepare("SELECT * FROM clients WHERE client_ID LIKE '%" . $searchvalue . "%' OR first_name LIKE '%" . $searchvalue . "%' OR last_name LIKE '%" . $searchvalue . "%' OR address LIKE '%" . $searchvalue . "%' OR gender LIKE '%" . $searchvalue . "%' OR notes LIKE '%" . $searchvalue . "%' OR manufacturer LIKE '%" . $searchvalue . "%'");
$STH->execute();
while($result = $STH->fetch(PDO::FETCH_ASSOC))
{
$manufacturer = $result['manufacturer'];
$clientID = $result['client_ID'];
$fname = $result['first_name'];
$lname = $result['last_name'];
$address = $result['address'];
$gender = $result['gender'];
$notes = $result['notes'];
?>
<tr bgcolor="lightblue">
<td bgcolor="lightblue">
<?php echo $clientID ?>
</td>
<td bgcolor="lightblue">
<?php echo $fname ?>
</td>
<td bgcolor="lightblue">
<?php echo $lname ?>
</td>
<td bgcolor="lightblue">
<?php echo $address ?>
</td>
<td bgcolor="lightblue">
<?php echo $manufacturer?>
</td>
<td bgcolor="lightblue">
<?php echo $gender ?>
</td>
<td bgcolor="lightblue">
<?php echo $notes ?>
</td>
<td bgcolor="lightblue">
<form action= "" method="post" role="form">
<input type = "submit" name ="delete" class="btn btn-inverse" value="Delete Client#<?php echo $clientID ?>" >
<input type = "submit" name = "modify" class="btn btn-inverse" value="modifyClient#<?php echo $clientID ?>" >
</form>
</td>
</tr>
<?php
}
}
else
{
$STH = $DBH->prepare('SELECT * FROM clients');
$STH->execute();
while($result = $STH->fetch(PDO::FETCH_ASSOC))
{
$manufacturer = $result['manufacturer'];
$clientID = $result['client_ID'];
$fname = $result['first_name'];
$lname = $result['last_name'];
$address = $result['address'];
$gender = $result['gender'];
$notes = $result['notes'];
?>
<tr bgcolor="lightblue">
<td><input type="checkbox" /></td>
<td bgcolor="lightblue">
<?php echo $clientID ?>
</td>
<td bgcolor="lightblue">
<?php echo $fname ?>
</td>
<td bgcolor="lightblue">
<?php echo $lname ?>
</td>
<td bgcolor="lightblue">
<?php echo $address ?>
</td>
<td bgcolor="lightblue">
<?php echo $manufacturer?>
</td>
<td bgcolor="lightblue">
<?php echo $gender ?>
</td>
<td bgcolor="lightblue">
<?php echo $notes ?>
</td>
<td bgcolor="lightblue">
<form action= "" method="post" role="form">
<input type = "submit" name ="delete" class="btn btn-inverse" value="Delete Client#<?php echo $clientID ?> ">
<input type = "submit" name = "modify" class="btn btn-inverse" value="modifyClient#<?php echo $clientID ?>" >
</form>
</td>
</tr>
<?php
} }
?>
</table>
<form action= "" id="test" method="post" role="form">
<button name="add" type="submit" class="btn btn-default">Add</button>
<input type ="submit" value="Print" onclick="printPage('printTable')"/>
<button name="SummaryReport" type="submit" class="btn btn-default">Summary Report</button>
</form>
<div class = "navbar navbar-default navbar-fixed-bottom"/>
<div class = "container">
<p class = "navbar-text">Site built by Super Red</p>
</div>
</body>
</html>
I dont know whether or not it is my print function or some other general error. Any advice would be appreciated!

<script language="javascript" type ="text/javascript" >
function printTbl() {
var TableToPrint = document.getElementById('ctl00_ContentPlaceHolder1_FormView1');
newWin = window.open("");
newWin.document.write(TableToPrint.outerHTML);
newWin.print();
newWin.close();
return false;
}

Related

Changing background color onclick on a specific table row

I want to change the background color of a specific clicked table row. It also should change it back to the original color. Back and forth from red to green. And it should also check the checkbox. Green = checkbox checked/ Red = checkbox unchecked.
The rows look like this
<tr id="<?php echo $row['id'] ?>" value="<?php echo $row['id'] ?>">
and for JQUERY I have this:
$(document).ready(function() {
$('.table tr').click(function(event) {
var id = $(this).attr('id');
var bcolor = $('.task').css('background-color');
console.log(id);
console.log(bcolor);
if (event.target.type !== 'checkbox') {
$(':checkbox', this).trigger('click');
if (bcolor == 'rgb(205, 92, 92)') {
$('.task').css('background-color', 'green');
} else {
$('.task').css('background-color', 'indianred');
}
};
});
});
How can I use the var id = $(this).attr('id'); to change the background color only for the specific clicked row?
Right now it makes every row green by clicking on any of them.
Whole main.php:
Header
<?php include 'taskpdo.php';?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>To Do List</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="jquery-3.4.1.min.js"></script>
<script src="script.js"></script>
</head>
Body
<body>
<!-- CONFIRM MESSAGE -->
<?php if (isset($_SESSION['message'])): ?>
<div class="msg">
<?php
echo $_SESSION['message'];
unset($_SESSION['message']);
?>
</div>
<?php endif?>
<div class="spacer">
<!-- Heading -->
<div class="heading">
<h2>To Do List</h2>
</div>
<!-- Userinformation -->
<div class="logout">
<?php if (isset($_SESSION['username'])): ?>
<p>Welcome<strong><?php echo $_SESSION['username']; ?></strong></p>
<p>logout</p>
<?php endif?>
</div>
</div>
Table
<table class="table">
<thead>
<tr>
<th>Check</th>
<th>UID</th>
<th>Username</th>
<th>Num</th>
<th>Tasks</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$tasks = sqlsrv_query($db,
"SELECT * FROM todo
join registrieren
on username = ersteller
where username = '" . $_SESSION['username'] . "'");
Rows
$i = 1;
while ($zeile = sqlsrv_fetch_array($tasks)) {
?>
<tr id="<?php echo $zeile['id'] ?>" type="checkbox" name="check[]" value="<?php echo $zeile['id'] ?>">
<td class="task"><input type="checkbox" id="check--<?php echo $zeile['id'] ?>"></td>
<input type="hidden" name="id" value="<?php echo $zeile['id']; ?>">
<td class="task" ><?php echo $zeile['uid'] ?></td>
<td class="task" ><?php echo $zeile['username'] ?></td>
<td class="task" ><?php echo $zeile['id'] ?></td>
<td class="task" id="<?php echo $zeile['id'] ?>" ><?php echo $zeile['task'] ?></td>
<td class="task" onclick="myFunction(<?php echo $zeile['id'] ?>)">
<form method="post" action="main.php">
<button type="submit" name="edit">
Edit
</button>
<input type="hidden" name="id" value="<?php echo $zeile['id']; ?>">
<input type="hidden" name="task" value="<?php echo $zeile['task']; ?>">
</form>
</td>
<td class="task" onclick="myFunction(<?php echo $zeile['id'] ?>)">
<form method="post" action="main.php" >
<button type="submit" name="delete">
Delete
</button>
<input type="hidden" name="id" value="<?php echo $zeile['id']; ?>">
</form>
</td>
</tr>
<?php
$i++;}
?>
</tbody>
</table>
Buttons
<form method="post" action="main.php" class="input_form">
<input type="hidden" name="ersteller" value="<?php echo $_SESSION['username']; ?>">
<?php
if ($update == true): ?>
<input type="text" name="task" class="task_input" value="<?php echo $task ?>">
<button type="submit" name="update" id="add_btn" class="add_btn">Update</button>
<input type="text" name="id" value="<?php echo $id ?>">
<?php else: ?>
<input type="text" name="task" class="task_input">
<button type="submit" name="addtask" id="add_btn" class="add_btn">Add Task</button>
<input type="hidden" name="id" value="<?php echo $id ?>">
<?php endif ?>
</form>
</body>
</html>
You can use toggleClass of jQuery:
// css for put in your element
.common-class {
background-color: #ff0000; // replace for your color
}
.highlight-class {
background-color: #0000ff !important; // replace for your color
}
$('your-selector').toggleClass('highlight-class'); // jQuery
Bensilson's answer helped me and i want to clarify what i have done:
I delete the class='task'inside the <td> and put it into the <tr> - Tag.
I've done a .highlighttask{background-color: green !important} inside the css.
And inside the js i've done
$(document).ready(function() {
$(".table tr").on('click', function() {
var checked = $(this).find('input[type="checkbox"]');
checked.prop('checked', !checked.is(':checked'));
$(this).toggleClass('highlighttask');
});
});
Now it overrights the background-color on a specific row AND it checks the checkbox of the specific row.
Thanks!

How to execute query saving using a <td> input that takes information from two different sql tables?

How can I fix this because it only saves the IDNumber of the borrower on a table and I need to have the book as well as the borrowers information saved when I click the "Issue" on the table? Thank you so much.
This is my issue.php
<?php
$fBookCode = $_GET['fBookCode'];
include_once('includes/connection_db.php');
$sql = " SELECT * FROM tblbooks WHERE fBookCode = '$fBookCode'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_assoc($result))
{
?>
<html>
<head>
<title>BCT Library </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- jQuery library -->
<script src="js/jquery.min.js"></script>
<!-- Popper JS -->
<script src="js/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="js/bootstrap.min.js"></script>
<script src="js/myStyle.js"></script>
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" type ="text/css" href="css/myStyle.css">
<link rel="stylesheet" href="js/myscript.js">
<?php
include_once('includes/connection_db.php')
?>
</head>
<body>
<?php include_once('includes/header.php');?>
<!-- NAVIGATION BAR CODE :P -->
<br>
<div class="container">
<div class="col-md-offset-5">
<ul class="nav nav-bar">
<div class="dropdown">
<li class="nav-item">
<a class="nav-link active" href="index.php">Books</a>
</li>
</div>
<div class="dropdown">
<button class="btn btn-warning dropdown-toggle" type="button" data-toggle="dropdown">TRANSACTIONS
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li>Borrowing</li>
<li>Returning</li>
</ul>
</div>
<div class="dropdown">
<button class="btn btn-warning dropdown-toggle" type="button" data-toggle="dropdown">BORROWERS
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li>Students</li>
<li>Employees</li>
</ul>
</div>
<div class="dropdown">
<button class="btn btn-warning dropdown-toggle" type="button" data-toggle="dropdown">REPORTS
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li>Generate Report</li>
</ul>
</div>
<div class="dropdown">
<button class="btn btn-warning dropdown-toggle" type="button" data-toggle="dropdown">ACCOUNT
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li>Users</li>
<li>Logout</li>
</ul>
</div>
</ul>
</div>
<br>
<!-- Modal for adding student-->
<div class="container">
<div class ="row">
<div class ="col-md-12">
<div class = "row">
</div>
<hr>
<h5><small><center><b>SELECT BORROWER</b></center></small></h5>
<hr>
<h5> <?php echo $row['fBookCode']; ?>  </h5>
<h5> <?php echo $row['fTitle']; ?>  </h5>
<h5> <?php echo $row['fAuthor']; ?>  </h5>
<form method="POST" action="">
<form method="POST" action="">
Search Borrower <input type="text" class = "search" name="fItems" />
<button class = "submit1" name="Search"> Search </button>
</form>
<table>
<thead>
<th> ID Number </th>
<th> Name </th>
<th> Strand/Course </th>
<th> Grade/Year </th>
<th> Gender </th>
<th> Issue </th>
</thead>
<tbody>
<?php
if(isset($_POST['Search']))
{
$item = $_POST['fItems'];
$sql = "SELECT * FROM tblstudents WHERE fIDNumber LIKE '%".$item."%' or fLastName LIKE '%".$item."%'";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_assoc($result))
{
?>
<tr>
<td><center> <?php echo $row['fIDNumber']; ?>  </center></td>
<td> <?php echo $row['fLastName'].", ".$row['fFirstName']." ".substr($row['fMiddleName'],0,1)."."; ?> </td>
<td> <?php echo $row['fCourse']; ?>  </td>
<td> <?php echo $row['fYear']; ?>   </td>
<td> <?php echo $row['fGender']; ?>  </td>
<form method="POST" action="includes/transactionsaving.php?fIDNumber=<?php echo $row['fIDNumber'];?>">
<td> <input type="submit" name="btnIssue" value="Issue"> </td>
</form>
</tr>
<?php
}
}
?>
</tbody>
</table>
<br>
<table>
<thead>
<th> ID Number </th>
<th> Name </th>
<th> Position </th>
<th> Gender </th>
<th> Issue </th>
</thead>
<tbody>
<?php
if(isset($_POST['Search']))
{
$item = $_POST['fItems'];
$sql = "SELECT * FROM tblemployee WHERE fIDNumber LIKE '%".$item."%' or fLastName LIKE '%".$item."%'";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_assoc($result))
{
?>
<tr>
<td><center> <?php echo $row['fIDNumber']; ?>  </center></td>
<td> <?php echo $row['fLastName'].", ".$row['fFirstName']." ".substr($row['fMiddleName'],0,1)."."; ?> </td>
<td> <?php echo $row['fPosition']; ?>  </td>
<td> <?php echo $row['fGender']; ?>  </td>
<form method="POST" action="includes/transactionsaving.php?fIDNumber=<?php echo $row['fIDNumber']; ?>">
<td> <input type="submit" name="btnIssue" value="Issue"> </td>
</form>
</tr>
<?php
}
}
?>
</tbody>
</table>
</form>
</div>
</div>
</div>
<br>
<br>
<!-- FOOTER -->
<div class="footer">
<div class = "row>"
<div class = "col-md-12">
<img src ="Images/footer.png" class = "img-responsive"/>
<br>
<p class ="text-center2"> © Copyright 2015. Baguio College of Technology. <br>All Rights Reserved.
37 Harrison Road, Baguio City <br>2600 Philippines</p>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
<?php
include_once('includes/connection_db.php')
?>
</body>
</html>
This is my transactionsaving.php and it can only save the IDNumber of the borrower + incorrect datetime borrowed because it kept getting error of Undefined Index for the others..
<?php
$fBookCode = "";
$fTitle = "";
$fAuthor = "";
$fIDNumber = "";
$fLastName = "";
$fFirstName = "";
$fMiddleName = "";
$fDateBorrowed = "";
$fDateReturned = "";
$fPenalty = "";
if(isset($_POST['btnIssue']))
{
//$fBookCode = $_POST['fBookCode'];
//$fTitle = $_POST['fTitle'];
// $fAuthor = $_POST['fAuthor'];
$fIDNumber = $_GET['fIDNumber'];
//$fLastName = $_POST['fLastName'];
//$fFirstName = $_POST['fFirstName'];
//$fMiddleName = $_POST['fMiddleName'];
$fDateBorrowed = date("Y-m-d h:i:sa");
//$fDateReturned = $_POST['fDateReturned'];
//$fPenalty = $_POST['fPenalty'];
$localhost = 'localhost';
$username = 'root';
$password = '';
$dbname = 'bctlibrary db';
$con = mysqli_connect($localhost, $username, $password, $dbname)
or die("FAILED CONNECTION");
$sql = "INSERT INTO tbltransactions
(fBookCode,
fTitle,
fAuthor,
fIDNumber,
fLastName,
fFirstName,
fMiddleName,
fDateBorrowed,
fDateReturned,
fPenalty)
VALUES
('$fBookCode',
'$fTitle',
'$fAuthor',
'$fIDNumber',
'$fLastName',
'$fFirstName',
'$fMiddleName',
'$fDateBorrowed',
'$fDateReturned',
'$fPenalty')";
$result = mysqli_query($con,$sql)or die ("QUERY ERROR ". mysqli_error($con));
mysqli_close($con);
}
?>
There is a nested form in your code
<form method="POST" action="">
<form method="POST" action="">
This is not a valid HTML. I think your problems are related to this. See answers to this StackOverflow question for workarounds.
Hope this helps! Cheers!

This Cookie works on Localhost But it doesn't work on main site

This Cookie works on Localhost But it doesn't work on the main site.
Help!! me guys.
I tried everything and did everything but still, it didn't work.I searched everywhere about this problem and found nothing about it.Therefore,I posted here so i could solve this issue.Also,Is there any other easy methods or hacks for this specific problem??
<?php
$connect = new PDO("mysql:host=localhost;dbname=pramit", "root", "");
$message = '';
if(isset($_POST["add_to_favourite"]))
{
if(isset($_COOKIE["event_c"]))
{
$cookie_data = stripslashes($_COOKIE['event_c']);
$event_data = json_decode($cookie_data, true);
}
else
{
$event_data = array();
}
$event_id_list = array_column($event_data, 'event_id');
if(in_array($_POST["hidden_id"], $event_id_list))
{
foreach($event_data as $keys => $values)
{
if($event_data[$keys]["event_id"] == $_POST["hidden_id"])
{
$event_data[$keys]["event_quantity"] = $event_data[$keys]["event_quantity"] + $_POST["quantity"];
}
}
}
else
{
$event_array = array(
'event_id' => $_POST["hidden_id"],
'event_name' => $_POST["hidden_name"],
'event_date' => $_POST["hidden_date"],
'event_quantity' => $_POST["quantity"]
);
$event_data[] = $event_array;
}
$event_data = json_encode($event_data);
setcookie('event_c', $event_data, time() + (86400 * 30));
header("location:index.php?success=1");
}
if(isset($_GET["action"]))
{
if($_GET["action"] == "delete")
{
$cookie_data = stripslashes($_COOKIE['event_c']);
$event_data = json_decode($cookie_data, true);
foreach($event_data as $keys => $values)
{
if($event_data[$keys]['event_id'] == $_GET["id"])
{
unset($event_data[$keys]);
$event_data = json_encode($event_data);
setcookie("event_c", $event_data, time() + (86400 * 30));
header("location:index.php?remove=1");
}
}
}
if($_GET["action"] == "clear")
{
setcookie("event_c", "", time() - 3600);
header("location:index.php?clearall=1");
}
}
if(isset($_GET["success"]))
{
$message = '
<div class="alert alert-success alert-dismissible">
×
Event Added to favourite
</div>
';
}
if(isset($_GET["remove"]))
{
$message = '
<div class="alert alert-success alert-dismissible">
×
Event Removed
</div>
';
}
if(isset($_GET["clearall"]))
{
$message = '
<div class="alert alert-success alert-dismissible">
×
Your Favourite is cleared....You are free to go..........
</div>
';
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Event Favourite</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<br />
<div class="container">
<br />
<h3 align="center">Event Favourite</h3><br />
<br /><br />
<?php
$query = "SELECT * FROM event_favourite ORDER BY id ASC";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
?>
<div class="col-md-3">
<form method="post">
<div style="border:1px solid #333; background-color:#f1f1f1; border-radius:5px; padding:16px;" align="center">
<img src="images/<?php echo $row["image"]; ?>" class="img-responsive" /><br />
<h4 class="text-info"><?php echo $row["name"]; ?></h4>
<h4 class="text-danger"> <?php echo $row["date"]; ?></h4>
<!-- <input type="text" name="quantity" value="1" class="form-control" />-->
<input type="hidden" name="hidden_name" value="<?php echo $row["name"]; ?>" />
<input type="hidden" name="hidden_date" value="<?php echo $row["date"]; ?>" />
<input type="hidden" name="hidden_id" value="<?php echo $row["id"]; ?>" />
<input type="submit" name="add_to_favourite" style="margin-top:5px;" class="btn btn-success" value="Add to favourite" />
</div>
</form>
</div>
<?php
}
?>
<div style="clear:both"></div>
<br />
<h3>Event Details</h3>
<div class="table-responsive">
<?php echo $message; ?>
<div align="right">
<b>Clear Event</b>
</div>
<table class="table table-bordered">
<tr>
<th width="40%">Event Name</th>
<th width="1%">---</th>
<th width="20%">date</th>
<th width="1%">----</th>
<th width="5%">Action</th>
</tr>
<?php
if(isset($_COOKIE["event_c"]))
{
$total = 0;
$cookie_data = stripslashes($_COOKIE['event_c']);
$event_data = json_decode($cookie_data, true);
foreach($event_data as $keys => $values)
{
?>
<tr>
<td><?php echo $values["event_name"]; ?></td>
<td><?php echo $values["event_quantity"]; ?></td>
<td> <?php echo $values["event_date"]; ?></td>
<td> <?php// echo number_format($values["event_quantity"] * $values["event_date"], 2);?></td>
<td><span class="text-danger">Remove</span></td>
</tr>
<?php
//$total = $total + ($values["event_quantity"] * $values["event_date"]);
}
?>
<tr>
<td colspan="3" align="right"></td>
<td align="right"> <?php// echo number_format($total, 2); ?></td>
<td></td>
</tr>
<?php
}
else
{
echo '
<tr>
<td colspan="5" align="center">No Event Added to favourite</td>
</tr>
';
}
?>

Can I put <form> in table as a modal

I have a question about form in table if I put the form inside the table as a modal there is a red bar and dont equal to the end tag form, I would like to know if im following rules or bad coding in html?
<table>
<thead>
<tr>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<?php
$conn = mysqli_connect($servername, $username, $password, $database);
$id=$_GET["id"];
$sqls = "SELECT resident_id, complaints_id, nature_of_complaints, status
FROM table_complaints WHERE resident_id=?";
mysqli_stmt_store_result($stmt );
if (mysqli_stmt_num_rows($stmt ) > 0) {
while(mysqli_stmt_fetch($stmt )) { ?>
<tr>
<td style="text-transform: capitalize"><?php echo
substr($nature_of_complaints,0,8);?>..</td>
<td style="text-transform: capitalize"><?php
echo $status?></td>
<td><a href="#" onclick="document.getElementById('id016<?php echo
$complaints_id?>').style.display='block'" >Add</a></td>
</tr>
<div id="id016<?php echo $complaints_id?>" class="modal">
<div class="modal-content">
<header>
<p>Involvement</p>
</header>
<form action="involvement.php" method="POST">
<input name="resid" value="<?php echo $resident_id?>" type="hidden">
<input name="compid" value="<?php echo $complaints_id?>" type="hidden">
<input type="submit" name="submit" value="Add">
</form>
</div>
<footer>
<button type="button" onclick="document.getElementById('id016<?php echo
$complaints_id?>').style.display='none'">Close</button>
</footer>
<?php
}
} else { ?>
<tbody><tr><td><?php echo "No Complaints";?></td></tr></tbody>
<?php
}
</table>

Search result on click of button in popup

I want to display search result on click of button, but my code is giving me the search result without click on button.
I think it's giving me the query result not the search result.
This code is working fine when I display the result on the page, but as per my requirement I want to display the search result on a popup.
I have used jquery popup.
<body><form action="#" method="POST"><body><form action="#" method="POST"><div data-role="page">
<div data-role="main" class="ui-content" >
Smart Search
</div>
<div data-role="popup" id="a" class="col-sm-6 ui-content">
<div class="input-group col-sm-8">
<input type="text" name="query" class="form-control" placeholder="Search Products to Buy..." " />
<span class="input-group-btn">
<button name ="search_btn" id ="search class="btn btn-warning" type="submit" value="Search" style="background-color:orange;">Search</button>
</span>
</div><div class="input-group col-sm-8 " ><table class="table table-hover">
<thead >
<tr bgcolor="#1E90FF">
<th>Products</th>
<th>Details</th>
<th>Retailers</th>
<th>Price</th>
<th>Buy</th>
</tr>
</thead>
</div><?php
error_reporting(0);
mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());
mysql_select_db("wordpress") or die(mysql_error());
?><?php $query = $_POST['query']; $query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results=mysql_query("select feed_product_image,feed_product_name,price,deeplink,image from wp_pc_products_merchants e,wp_pc_products w where e.slug=w.id_merchant and feed_product_name LIKE '%".$query."%'") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0)
{
while($results = mysql_fetch_array($raw_results))
{ ?><div class="input-group col-sm-8" style="text-align:center;margin-top:10px;"><tbody>
<tr>
<td><img src = "<?php echo $results['feed_product_image']; ?>" style="object-fit:contain;height:70px;width:100px;" /></td>
<td><?php echo "<p>".$results['feed_product_name']. "</p>" ; ?></td>
<td><img src = "<?php echo $results['image']; ?>" style="background-size:contain;height:40px;width:120px;" /></td>
<td><?php echo '<i class="fa fa-inr"> '.$results['price']. '</i>'.".00" ; ?></td>
<td>Buy now</td>
</tr>
</tbody>
</div>
<?php
}
}
else
{ // if there is no matching rows do following
echo "No results";
}
?>
</div>
</form>
</div>
This will give you search results in modal popup. I have changed your code around a bit. You can popup in case of no search results too.
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="main" class="ui-content" >
Smart Search
</div>
<div data-role="popup" id="a" class="col-sm-6 ui-content">
<div class="input-group col-sm-8">
<form method="POST">
<input type="text" name="query" class="form-control" placeholder="Search Products to Buy..." " />
<span class="input-group-btn">
<button name ="search_btn" id ="search" class="btn btn-warning" type="submit" value="Search" style="background-color:orange;">Search</button>
</span>
</form>
</div>
<?php
if(isset($_POST['query']) && $_POST['query']!="" ) {
error_reporting(0);
mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());
mysql_select_db("wordpress") or die(mysql_error());
$query = $_POST['query']; $query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results=mysql_query("select feed_product_image,feed_product_name,price,deeplink,image from wp_pc_products_merchants e,wp_pc_products w where e.slug=w.id_merchant and feed_product_name LIKE '%".$query."%'") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0)
{
?>
<div class="input-group col-sm-8 modal-box" id="popup" title="Search Results" style="text-align:center;margin-top:10px;">
<table class="table table-hover">
<thead >
<tr bgcolor="#1E90FF">
<th>Products</th>
<th>Details</th>
<th>Retailers</th>
<th>Price</th>
<th>Buy</th>
</tr>
</thead>
<tbody>
<?php
while($results = mysql_fetch_array($raw_results))
{ ?>
<tr>
<td><img src = "<?php echo $results['feed_product_image']; ?>" style="object-fit:contain;height:70px;width:100px;" /></td>
<td><?php echo "<p>".$results['feed_product_name']. "</p>" ; ?></td>
<td><img src = "<?php echo $results['image']; ?>" style="background-size:contain;height:40px;width:120px;" /></td>
<td><?php echo '<i class="fa fa-inr"> '.$results['price']. '</i>'.".00" ; ?></td>
<td>Buy now</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php
}
else
{ // if there is no matching rows do following
echo "No results";
}
}
?>
</div>
</form>
</div>
<script>
$(function() {
$( "#popup" ).dialog();
});
</script>

Categories