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>
Related
I have this controller:
<?php
class Cart extends CI_Controller{
public $paypal_data = '';
public $tax;
public $shipping;
public $total = 0;
public $grand_total;
/*
*Cart Index
*/
public function index(){
//Load view
$data['main_content'] = 'cart';
$this->load->view('layouts/main', $data);
}
/*
*Add To Cart
*/
public function add(){
//Item data
$data = array(
'id'=> $this->input->post('item_number'),
'qty'=> $this->input->post('qty'),
'price'=> $this->input->post('price'),
'name'=> $this->input->post('title'),
);
//print_r($data);die();
//Insert Into cart-block
$this->cart->insert($data);
redirect('products');
}
}
And I have the view file which uses this controller:
<div class="cart-block">
<form action="cart/update" method="post">
<table cellpadding="6" cellspacing="1" style="width:100%" border="0">
<tr>
<th>QTY</th>
<th>Item Description</th>
<th style="text-align:right">Item Price</th>
</tr>
<?php $i = 1; ?>
<?php foreach ($this->cart->contents() as $items) : ?>
<input type="hidden" name="<?php echo $i. '[rowid]'; ?>" value="<?php echo $items['rowid']; ?>" />
<tr>
<td><input type="text" name="<?php echo $i.'[qty]'; ?>" value="<?php echo $items['qty']; ?>" maxlength="3" size= "5"</td>
<td><?php echo $items['name']; ?></td>
<td style="text-align:right"><?php echo $this->cart->format_number($items['price']); ?></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td></td>
<td class="right"><strong>Total</strong></td>
<td class="right" style="text-align:right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</table>
<br>
<p><button class="btn btn-default" type="submit">Update Cart</button>
<a class="btn btn-default" href="cart">Go To Cart</a></p>
</form>
</div>
<div class="panel panel-default panel-list">
<div class="panel-heading panel-jeading-dark">
<h3 class="panel-title">
Categories
</h3>
</div>
<!--List group -->
<ul class="list-group">
<?php foreach(get_categories_h() as $category) : ?>
<li class="list-group-item"><?php echo $category->name; ?></li>
<?php endforeach; ?>
</ul>
I apologize that I can't show you the actual website because it's not online but based on the above snippets can any point out an error in the view file or controller that causes the shopping cart not to update?
I'm following a video tutorial but it seems I'm doing something wrong. Here is the video: https://youtu.be/ajt_DJMS5FM?t=13m45s
Your form action is cart/update your function in the controller is add?
Change the form action to cart/add. Or write an cart/update function.
Firstly change the Form Action action="cart/update" to
action="<?php echo base_url();?>cart/add" and apply die(); and test it
load the cart library in controller
$this->load->library('cart');
I have a view code:
<?php
$i = 1;
//var_dump($this->productList);
foreach ($this->productList as $data) {
$desc=explode(",",$data['descriptions']);
?>
<tr>
<th colspan="3">
<input type="hidden" id="id_pack" name="id_pack" value="<?php echo $data['package_id']; ?>">
<input type="hidden" id="nama_pack" name="nama_pack" value="<?php echo $data['package_name']; ?>">
<h4 align="center" class="title-pack"><?php echo $data['package_name']; ?></h4>
</th>
</tr>
<tr id="dashe">
<td>
<ul class="myul">
<?php foreach($desc as $descriptions) { ?>
<li class="myli"> <?php echo $descriptions; ?></li>
<?php } ?>
</ul>
</td>
<td>
<h4 class="prize">
Rp. <?php echo number_format($data['price'],2);?>
/ month
</h4>
</td>
<td>
<p id="order" name="order" class="mybutton" data-toggle="modal" data-target=".mymodal">Order</p>
</td>
</tr>
<?php
$i++;
}
?>
And this the javascript:
document.getElementById("order").addEventListener("click", tampilkanHrm);
function tampilkanHrm() {
var pilihan=$("#nama_pack").val();
document.getElementById("choice").innerHTML = pilihan;
document.getElementById("pack").value = pilihan+" Package";
}
the problem is, in the order button it always show the same record. Just show the first data, even i clicked other order button. Hope somebody help.
You can't assign same id for multiple elements.
So, have different ids.
<?php
$i = 1;
//var_dump($this->productList);
foreach ($this->productList as $data) {
$desc=explode(",",$data['descriptions']);
?>
<tr>
<th colspan="3">
<input type="hidden" id="id_pack<?php echo $i ?>" name="id_pack" value="<?php echo $data['package_id']; ?>">
<input type="hidden" id="nama_pack<?php echo $i ?>" name="nama_pack" value="<?php echo $data['package_name']; ?>">
<h4 align="center" class="title-pack"><?php echo $data['package_name']; ?></h4>
</th>
</tr>
Similarly create buttons with different ids.
<td>
<p id="<?php echo $i ?>" name="order" class="mybutton" data-toggle="modal" data-target=".mymodal">Order</p>
</td>
Then change your javascript to jquery. Hope, you might also be using jquery [ understood from your code ]
$(".mybutton").on("click", function() {
var identifier = $(this).attr("id");
var pilihan=$("#nama_pack"+identifier).val();
$("#choice").html(pilihan);
});
Change your code like this and check.
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;
}
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>
My check box when unchecked my input with id of delete should be disabled, but for some reason the java script code it not picking up the id of both input and checked input. I use bootstrap 3 and codeigniter.
What's wrong with my code? Unsure why not working. All JS scripts loaded correct.
<script type="text/javascript">
$('#check_delete').click(function(){
if($(this).attr('checked') == false){
$('input #delete').attr("disabled","disabled");
} else {
$('input #delete').removeAttr('disabled');
}
});
</script>
<input type="submit" role="button" class="btn btn-danger" id="delete" value="Delete">
View
<?php echo form_open('admin/users_group/delete');?>
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
<th class="text-left">User Group ID</th>
<th class="text-left">Name</th>
<th class="text-right">Action</th>
</tr>
</thead>
<?php if ($users_group == TRUE) {?>
<?php foreach ($users_group as $user_group) { ?>
<tr>
<td class="text-center"><?php if (in_array($user_group['user_group_id'], $selected)) { ?>
<input type="checkbox" id="check_delete" name="selected[]" value="<?php echo $user_group['user_group_id']; ?>" checked="checked" />
<?php } else { ?>
<input type="checkbox" id="check_delete" name="selected[]" value="<?php echo $user_group['user_group_id']; ?>" />
<?php } ?>
</td>
<td class="text-left"><?php echo $user_group['user_group_id']; ?></td>
<td class="text-left"><?php echo $user_group['name']; ?></td>
<td class="text-right">
<input type="submit" role="button" class="btn btn-danger" id="delete" value="Delete">
<i class="fa fa-pencil"></i> Edit</td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="text-center" colspan="3">No Results</td>
</tr>
<?php } ?>
</table>
</div>
<?php echo form_close();?>
</div>
<div class="panel-footer clearfix">
<div class="pull-left pag-user-group"><?php echo $pagination; ?></div>
<div class="pull-right" style="padding-top: 7.5px;"><?php echo $results; ?></div>
</div>
</div>
</div>
</div>
</div><!-- # Page Inner End -->
</div><!-- # Page End -->
</div><!-- # Wrapper End -->
<script type="text/javascript">
$('#check_delete').click(function(){
if($(this).attr('checked') == false){
$('input #delete').attr("disabled","disabled");
} else {
$('input #delete').removeAttr('disabled');
}
});
</script>
You declare your script before the HTML code.
A HTML page is read sequentially.
alert( $('input#delete').length )
<input id="delete" >
This will alert "0" because jQuery looks for #delete, and then, next line, #delete exists.
Two solutions :
1) Move your script after HTML, at the end, before the </body> tag.
2) Wrap your code in $(function(){ /* Your code here */ } . This will wait for the page to be ready before executing the script.
<input id="delete" >
alert( $('input#delete').length )
This will work, and this also will :
$(function(){
alert( $('input#delete').length )
})
<input id="delete" >