I am trying to get checked values in unos.php file. I get empty post but could not figure it out where is mistake.
I want to check just one checkbox and according to post value received I will perform results.
<form method="post" action="unos.php">
<button type="submit" class="btn btn-primary" name="izmjena">Izmjena</button>
<table>
<thead>
<tr>
<th data-field="artikal" data-checkbox="true" > </th>
<th data-field="id" data-sortable="true">Id</th>
<th data-field="sifra" data-sortable="true">Sifra</th>
<th data-field="name" data-sortable="true">Naziv</th>
<th data-field="mjera" data-sortable="true">Jed. mjere</th>
<th data-field="stanjesa" data-sortable="true">Stanje Sa</th>
<th data-field="stanjebl" data-sortable="true">Stanje BL</th>
<th data-field="minkolicina" data-sortable="true">Min kolicina</th>
<th data-field="kategorija" data-sortable="true">Kategorija</th>
<th data-field="status" data-sortable="true">Status</th>
<th data-field="print" data-sortable="true">P</th>
</tr>
</thead>
<tbody>
<?php while ($r = $q->fetch()): ?>
<tr>
<td><input type="checkbox" name="artikli" value="<?.$r['ArtId'].?>"></td>
<td><?=$r['ArtId'] ?></td>
<td><?=$r['ArtSifra'] ?></td>
<td><?=$r['ArtNaziv'] ?></td>
<td><?=$r['JmNaziv'] ?></td>
<td><?=$r['ArtStanje']?></td>
<td><?=$r['ArtStanjeMo'] ?></td>
<td><?=$r['ArtMinKolic'] ?></td>
<td><?=$r['KatNaziv'] ?></td>
<td><?=$r['ArtAktivan'] ?></td>
<td><a onClick="window.open('kartica-artikla.php?id= <?=$r['ArtKategorija']?>','Websoft','width=800,height=500,left=0,top=100,screenX=0,screenY=100,menubar=yes,scrollbars=yes')" href "">
<img src="../../img/kartica.png" width="20"></td>
</tr>
<?php endwhile; ?>
</tbody>
<tfoot>
</tfoot>
</table>
file unos.php.. In this file I want to post value of checkbox
<?php
if (isset($_POST["izmjena"])) {
$id=$_POST["artikli"];
echo $id;
var_dump($id);
}
else{
}
Change:
<td><input type="checkbox" name="artikli" value="<?.$r['ArtId'].?>"></td>
To:
<td><input type="checkbox" name="artikli" value="<?php echo $r['ArtId']; ?>"></td>
Dont forget to close your form either :)
If you're using several checkboxes, you should be using an input checkbox with the following "name": "artikli[]".
The "[]" will send an array of values instead of sending a string.
Code:
<input type="checkbox" name="artikli[]" value="<?.$r['ArtId'].?>" />
checkbox's value will be present if it is checked. Do this -
$id=(!empty($_POST["artikli"])) ? $_POST["artikli"] : false;
and you are not echoing the whole html so no need to concate. Change -
<td><input type="checkbox" name="artikli" value="<? echo $r['ArtId'];?>"></td>
Related
I am buildingd a library management system in PHP and HTMl.
I have some problem with the borrowing system where user can borrow books.
Here is my emitere-carti.php:
<form action="imprumutare.php" method="POST">
<table class="table table-dark">
<thead>
<tr>
<th>Imprumutare</th>
<th scope="col">Titlu </th>
<th scope="col">Autor</th>
<th scope="col">Categorie</th>
<th scope="col">Stoc</th>
</tr>
</thead>
<tbody>
<?php
$selectare="SELECT * FROM carti";
$rezultat=mysqli_query($conn,$selectare);
if(mysqli_num_rows($rezultat)>0){
while($row=mysqli_fetch_assoc($rezultat)){
$carte_nume=$row['titlu'];
$disabled=$row['stoc']>0 ? "" :"disabled";
?>
<tr>
<td><input type="submit" name="test" class="btn btn-secondary"
value="Imprumutare" <?php echo $disabled;?>></input>
<td><input type="text" name="nume" value="<?php echo $row['titlu'];?
>"></input></td>
<td><?php echo $row['autor'];?></td>
<td><?php echo $row['categorie'];?></td>
<td><?php echo $row['stoc'];?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</form>
Here is my imprumutare.php(that means borrowing):
include('conexiune.php');
//sfarsit if
//Imprumutare
if(isset($_POST['test'])){
$id=$_POST['identificator'];
$nume_carte=$_POST['nume'];
$sql_rezervare="UPDATE carti SET stoc=stoc-1 WHERE
titlu='$nume_carte' ";
if( mysqli_query($conn,$sql_rezervare)){
header('location:emitere_carti.php');
}
else{
die(mysqli_error($conn));
}
}
Here is a screenshot about what I am talking:
So my problem is both buttons are decrementeing the same value(the value of stoc).
Can someone help me?
I am trying to process form fields via POST method. I will post a long code for you to inspect, however the structure of the code is simply like this
<form> <table> <th> </th> <td> </td> </table> </form>
so it is a table inside a form. When the form is submitted, I am taken to the "cart.php" page which is expected, but that page shows the echo statement and shows the variables correctly for a split second, then shows the rest of the page but the variables in the echo statement become "undefined".
P.S: Please don't mark as duplicate with this question, thanks.
This is the first page index.php
<div class="table-responsive" id="order_table">
<form method="POST" action="cart.php" class="form-group">
<table class="table table-bordered">
<tr>
<th width="40%">Product Name</th>
<th width="10%">Quantity</th>
<th width="20%">Price</th>
<th width="15%">Sub Total</th>
<th width="5%">Action</th>
</tr>
<?php
if(!empty($_SESSION["shopping_cart"]))
{
$sub_total = 0;
foreach($_SESSION["shopping_cart"] as $keys => $values)
{
?>
<tr>
<td><?php echo $values["product_name"]; ?></td>
<td><input type="text" name="quantity[]" id="quantity<?php echo $values["product_id"]; ?>" value="<?php echo $values["product_quantity"]; ?>" data-product_id="<?php echo $values["product_id"]; ?>" class="form-control quantity" /></td>
<td align="right">$ <?php echo $values["product_price"]; ?></td>
<td align="right">$ <?php echo number_format($values["product_quantity"] * $values["product_price"], 2); ?></td>
<td><button name="delete" class="btn btn-danger btn-xs delete" id="<?php echo $values["product_id"]; ?>">Remove</button></td>
</tr>
<?php
$sub_total = $sub_total + ($values["product_quantity"] * $values["product_price"]);
$tax = $sub_total * 0.075;
$total = $sub_total + $tax;
}
?>
<tr>
<td colspan="3" align="right"><span style="font-size:1.3em;">Tax</span></td>
<td align="right">$ <?php echo number_format($tax,2); ?></td>
</tr>
<tr>
<td colspan="3" align="right"><span style="font-size:1.3em;">Total</span></td>
<td align="right">$ <?php echo number_format($total, 2); ?></td>
<td></td>
</tr>
<tr>
<td colspan="5" align="center">
<textarea name="comments" id="comment" class="form-control" placeholder="Please enter any special instructions for the order"></textarea> <br>
<input type="submit" name="place_order" id="place_order" class="btn btn-warning" value="Place Order" />
</td>
</tr>
<?php
}
?>
</table>
</form>
And this is the beginning of cart.php:
$comment = $_POST['comments'];
echo $comment. $_POST['place_order'];
print_r($_POST);
How I know that the variables do get passed is cause I noticed some result appearing for a split second so I took a video and paused it there and it had the expected POST array, before the page suddenly appears as expected but with
"Undefined index: comments "
and
"Undefined index: place_order"
and "Array()" at the top. cart.php does not have any commands that make it refresh. Thank you.
I have a table with multiple columns (index.php). One column is a checkbox. Whenever the checkbox is checked, it displays another row where you can select a quantity. You can then hit a button called "Add to Order" and it will take you to a confirmation page (index-order.php) where I want it to display each row along with all of the data in that specified row that has the checkbox checked. Currently, I am getting no errors in my console, but no data is being displayed at all.
What do I need to change to make this happen? Here is what I have so far.
Index.php code:
<form name="form1" method="POST" action="index-order.php">
<section id="addToOrder">
<button type="submit" class="order" id="order" name="order" value="AddToOrder">Add to Order</button>
</section>
<br>
<div id="my-div2" class="ui-widget">
<div class="ui-widget">
<table id="merchTable" cellspacing="5" class="sortable">
<thead>
<tr class="ui-widget-header">
<th class="sorttable_nosort"></th>
<th class="sorttable_nosort">Loc</th>
<th class="merchRow">Report Code</th>
<th class="merchRow">SKU</th>
<th class="merchRow">Special ID</th>
<th class="merchRow">Description</th>
<th class="merchRow">Quantity</th>
<th class="sorttable_nosort">Unit</th>
<th style="display: none;" class="num">Quantity #</th>
</tr>
</thead>
<tbody>
<?php foreach ($dbh->query($query) as $row) {?>
<tr>
<td class="ui-widget-content"><input type="checkbox" class="check" name="check"></td>
<td name="rows[0][0][loc]" class="loc ui-widget-content" id="loc-<?php echo intval ($row['Loc'])?>"><?php echo $row['Loc'];?></td>
<td name="rows[0][0][rp-code]" class="rp-code ui-widget-content" align="center" id="rp-code-<?php echo intval ($row['Rp-Code'])?>"><?php echo $row['Rp-Code'];?></td>
<td name="rows[0][0][sku]" class="sku ui-widget-content" id="sku-<?php echo intval ($row['SKU'])?>"><?php echo $row['SKU'];?></td>
<td name="rows[0][0][special-id]" class="special-id ui-widget-content" align="center" id="special-id-<?php echo intval ($row['Special-ID'])?>"><?php echo $row['Special-ID'];?></td>
<td name="rows[0][0][description]" class="description ui-widget-content" id="description-<?php echo intval ($row['Description'])?>"><?php echo $row['Description'];?></td>
<td name="rows[0][0][quantity]" class="quantity ui-widget-content" data-quantity="<?php echo $row['Quantity'] ?>" align="center" id="quantity-<?php echo intval ($row['Quantity'])?>"><?php echo $row['Quantity'];?></td>
<td name="rows[0][0][unit]" class="unit ui-widget-content" id="unit-<?php echo intval ($row['Unit'])?>"><?php echo $row['Unit'];?></td>
<td name="rows[0][0][quant]" style="display: none;" class="quantity_num ui-widget-content"><input type="textbox" style="width: 100px;" class="spinner" name="value" id="test"></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</form>
Index-order.php:
<?php if(isset($_POST['rows'])): ?>
<table cellspacing="20">
<tr align="center">
<th>Loc</th>
<th>Report Code</th>
<th>SKU</th>
<th>Special ID</th>
<th>Description</th>
<th>Quantity</th>
<th>Unit</th>
<th>Quantity #</th>
</tr>
<?php
foreach($_POST['rows'][0] as $row):
?>
<tr align="center">
<td><?php echo $row['loc']; ?></td>
<td><?php echo $row['rp-code']; ?></td>
<td><?php echo $row['sku']; ?></td>
<td><?php echo $row['special-id']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['quant']; ?></td>
</tr>
<?php
endforeach;
?>
</table>
I am okay with the precedent answer, I never heard about this kind of method with PHP and it doesn't seems to be the right solution. Anyway, the following post would maybe help you : How to get value from td's via $_POST.
You cannot transfer datas through POST by using td ; but an alternative would be to use the "hidden" type of forms element :
<form action="script.php" method="post">
<td class=".."><input type="hidden" name="td1" value="...">value</td>
...
</form>
In PHP, you'll grab the data with the $_POST array and the td1 name :
<?php var_dump($_POST); ?>
Itwould in my opinion be the easier way to get what you want in a proper way ; the link I gave upper is also talking about DOMDocument, but it looks more complex to manage with.
I have been working on this script that should get the value of an id field in a database through a checkbox that will be used by a link to edit a page. I know there are topics relating to this but non deals with using the value of the checkbox in a link. The checkbox is actually getting the value of the id from the database i know this because i used inspect element in firefox to view the value of the checkbox. The issue I'm having is using this value in a link to edit a page. Any help will be appreciated. My script is displayed below.
<td width="341" height="73"><h1><strong><span class="style2">EVENTS </span></strong></h1></td>
<td width="59" align="right"><div align="right"><strong>New</strong></div></td>
<td width="66" align="right"><div align="right"><strong><a href="edit_event.php?id=<?php
if (isset ($chek)) {
echo urlencode($chek);
}
?>"/>Edit</a></strong></div></td>
<td width="82" align="right"><div align="right"><strong>Archive</strong></div></td>
<td width="79" align="right"><div align="right"><strong>Unarchive</strong></div></td>
<td width="70" align="right"><div align="right"><strong>Delete</strong></div></td>
<td width="71" align="right"><div align="right"><strong>Exit</strong></div></td>
</tr>
</table>
<p> </p>
<table width="786" border="1">
<tr valign="top">
<th width="46">Event Title</th>
<th width="27"><input type="checkbox" name="checkbox1" value="checkbox" /></th>
<th width="37">Start Date</th>
<th width="36">End Date</th>
<th width="43">Start Time</th>
<th width="38">End Time</th>
<th width="43">Venue</th>
<th width="45">Event Type</th>
<th width="94">Event Description</th>
<th width="152">Event Program</th>
<th width="79">Reminder Date</th>
<th width="70">Reminder Time</th>
</tr>
<?php foreach($events as $event): ?>
<tr valign="top">
<td><?php echo $event->event_title; ?></td>
<td> <form id="form1" name="form1" method="post" action="">
<?php echo "<input type=\"checkbox\" name=\"chek[]\" value= $event->event_id id=\"chek\"/>"; ?>
</form>
</td>
<td><?php echo $event->start_date; ?></td>
<td><?php echo $event->end_date; ?></td>
<td><?php echo $event->start_time; ?></td>
<td><?php echo $event->end_time; ?></td>
<td><?php echo $event->venue; ?></td>
<td><?php echo $event->event_type; ?></td>
<td><?php echo $event->event_description; ?></td>
<td><?php echo $event->event_program; ?></td>
<td><?php echo $event->reminder_date; ?></td>
<td><?php echo $event->reminder_time; ?></td>
</tr>
<?php endforeach; ?>
<?php
$check = $_POST['chek'];
if(empty($check)){
$$check="";
}else{
$N = count($check);
for($i=0; $i < $N; $i++){
$chek =($check[$i]);
}
}
?>
I don't know if my question is understood, what i meant is that I want the value of my check box to display after (http://localhost/emgt/admin/edit_event.php?id=) id so i can edit that particular row.
You can check with the below link. It may be helpful for you.
As far I see you need to add class, and id to your checkbox and use a jquery/javascript function to call the value in your href.
Pass checkbox value to Edit (using href)
Hope it would be of some help to you.
I'm sorry, i found your code to be a little unclear. If you mean calling a url with the checkbox value as a parameter you can do so by adding an "id" property to the checkbox element, and then calling the page like:
var chk = document.getElementById("checkbox_id");
var url = "http://localhost/emgt/admin/edit_event.php?id=" + chk.value;
location.href = url;
I have a database
that have two tables.
The sql query fetching data correctly.
I want to sort fields data by typing table heading in text box and click on go that in table footer.
Many Thanks
<table border="0" cellpadding="0" cellspacing="0" width="50%">
<thead>
<tr>
<th class="capt" colspan="6">Available Projects</th>
</tr>
<tr>
<th>Select</th>
<th>Project</th>
<th>Crawler</th>
<th>Description</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
include(dirname(__file__)."/includes/dbConn.php");
$result = mysql_query("SELECT *, ( SELECT name FROM projects WHERE projects.id = crawlers.pid ) AS pname FROM `crawlers`", $appConn);
while($row = mysql_fetch_array($result))
{
?>
<tr id="crawler_<?php echo $row['id']; ?>">
<td>
<input value="" id="check" type="checkbox">
<input id="crawler_id_<?php echo $row['id']; ?>" type="hidden" value="<?php $row['id']; ?>" /> <!-- crawler id -->
</td>
<td><?php echo $row['pname']; ?></td>
<td><?php echo $row['name']; ?></td>
<td>username#domain.com</td>
<td>Enabled</td>
<td><a class="edit" href="#">edit</a><a class="add" href="#">run</a><a class="delete" href="#">delete</a></td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th colspan="6"> Sort Fields by <input value="type here" id="field" type="text"> Go </th>
</tr>
</tfoot>
</table>
I think, you are looking for ORDER BY
Have a look at the MySQL Documentation about the SELECT syntax: http://dev.mysql.com/doc/refman/5.0/en/select.html