I want to disable the two buttons in a single row if the button will be clicked and won't affect the buttons of another row.
I dont know how to disable an echo button of the table. I want to disable the "Accept" and "Reject" button if one of those was been clicked.I provide a screenshot so that you can easily understand what I mean. Thank you in advance.
Here's my php code. It names as app.php
<?php
//connect to database
$con = mysqli_connect('127.0.0.1','root','');
//select database
mysqli_select_db($con, 'appointment');
//select query
$sql = "SELECT * FROM service";
//Execute the query
$records = mysqli_query($con,$sql)
?>
<html>
<head>
<title>Appointment Schedule</title>
</head>
<body>
<table width = "100%" border = "5px" height = "20%">
<tr align = "left">
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>Address</th>
<th>Date</th>
<th>Time</th>
<th>Office</th>
<th>Service</th>
<th>Contact No.</th>
<th>Remarks</th>
</tr>
<?php
while($row = mysqli_fetch_array($records))
{
echo "<tr><form action = 'display.php' method = post>";
echo "<input type=hidden name=id value='".$row['ID']."'>";
echo "<td>".$row['fname']."</td>";
echo "<td>".$row['mname']."</td>";
echo "<td>".$row['lname']."</td>";
echo "<td>".$row['address']."</td>";
echo "<td>".$row['date']."</td>";
echo "<td>".$row['time']."</td>";
echo "<td>".$row['office']."</td>";
echo "<td>".$row['services']."</td>";
echo "<td><name = number>".$row['contactno']."</td>";
echo "<td>".$row['remarks']."</td>";
echo "<td><input type =submit value='Accepted' name=accept>";
echo "<td><input type =submit value='Rejected' name=reject>";
echo "</form></tr>";
}
?>
</table>
</body>
</html>
here's my another one php code. It names display.php
<?php
//connect to database
$con = mysqli_connect('127.0.0.1','root','');
//select database
mysqli_select_db($con, 'appointment');
if($_POST['accept'])
{
$sql = "UPDATE service SET remarks = 'Accepted' WHERE ID=$_POST[id]";
}
else if($_POST['reject'])
{
$sql = "UPDATE service SET remarks = 'Rejected' WHERE ID=$_POST[id]";
}
//Execute Query
if(mysqli_query($con,$sql))
header("refresh:1; url=app.php");
else
echo "Unsuccessful";
?>
here's the screenshot of my work
Sample of my database table using php
Kindly try the below code:
Provide the condition to display the buttuon
echo "<td><input type =submit value='Accepted' name=accept>";
echo "<td><input type =submit value='Rejected' name=reject>";
if($row['remarks'] == 'Accepted' || $row['remarks'] == 'Rejected')
{
echo "<td><input type =submit disabled value='Accepted' name=accept>";
echo "<td><input type =submit disabled value='Rejected' name=reject>";
}
Related
HTML button not selecting correct form value.
The following code selects data and displays it correctly in a html table: fname, lname , customer_id and the last column in the table shows a button labelled more info.
The first part of the code works fine.
<table>
<thead>
<tr>
<th>First Name</th> <th>Last Name</th> <th>Customer ID</th><th>Info</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$sql = "select fname, lname,customer_id from customer_address ";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)){
$fname = $row['fname'];
$lname = $row['lname'];
$customer_id = $row['customer_id'];
echo" <tr>";
echo"<td>$fname</td>";
echo"<td>$lname</td>";
echo"<td>$customer_id</td>";
echo"<td><input type='hidden' name='customer_id' value='$customer_id'>";
echo "<button type='submit' name='submit'>More Info</button></td>" ;
}
echo" </tr>";
?>
</tbody>
</table>
</form>
With the second part of the code, I want to grab the customer_id when the button is clicked and display it below the table(I am going to uses the variable in a subsequent query to display more information later). The button selects the same customer_id no matter which button is clicked, and it is always the last record in the table. I would appreciate any help in correcting my error.
<?php
$ccf=" ";
if(isset($_POST['submit'])){
$ccf = $_POST['customer_id'];
}
echo "Customer Id selected is:$ccf";
?>
Your elements are all inside one form, so there are multiple elements with name='customer_id'. Place each row inside their own separate <form></form>:
<table>
<thead>
<tr>
<th>First Name</th> <th>Last Name</th> <th>Customer ID</th><th>Info</th>
</tr>
</thead>
<tbody>
<?php
$sql = "select fname, lname,customer_id from customer_address";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)){
$fname = $row['fname'];
$lname = $row['lname'];
$customer_id = $row['customer_id'];
echo" <tr>";
echo "<td>$fname</td>";
echo "<td>$lname</td>";
echo "<td>$customer_id</td>";
echo "<td>";
echo "<form action='' method='post'>";
echo "<input type='hidden' name='customer_id' value='$customer_id'>";
echo "<button type='submit' name='submit'>More Info</button>";
echo "</form>";
echo "</td>";
echo" </tr>";
}
?>
</tbody>
</table>
I'm not sure about the title, I tried my best.
I have a table displayed with information from a database using this file
display.php
<?php
mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("tournaments") or die(mysql_error());
$result = mysql_query("SELECT * FROM tournies")
or die(mysql_error());
echo '<table id="bets" class="tablesorter" cellspacing="0" summary="Datapass">
<thead>
<tr>
<th>Tournament <br> Name</th>
<th>Pot</th>
<th>Maximum <br> Players</th>
<th>Minimum <br> Players</th>
<th>Host</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>';
while($row = mysql_fetch_array( $result )) {
$i=0; if( $i % 2 == 0 ) {
$class = "";
} else {
$class = "";
}
echo "<tr" . $class . "><td>";
echo $row['tour_name'];
$tour_id = $row['tour_name'];
echo "</td><td>";
echo $row['pot']," Tokens";
echo "</td><td class=\"BR\">";
echo $row['max_players']," Players";
echo "</td><td class=\"BR\">";
echo $row['min_players']," Players";
echo "</td><td class=\"BR\">";
echo $row['host'];
echo "</td><td>";
echo "<input id=\"delete_button\" type=\"button\" value=\"Delete Row\" onClick=\"SomeDeleteRowFunction(this)\">";
echo "</td><td>";
echo "<form action=\"join.php?name=$name\" method=\"POST\" >";
echo "<input id=\"join_button\" type=\"submit\" value=\"Join\">";
echo "</td></tr>";
}
echo "</tbody></table>";
?>
Basically I want the user to press a button from a row of the table and they go to a new page called join.php. I need the persons username and the name of the tournament from the row the clicked.
For example here's my page:
When they click the join button at the end of row one it should send them to
'join.php?name=thierusernamehere&tourname=dfgdds'
Any help much appreciated. Thanks.
echo '<td>Join</td>'
There are many way to approach.
The easiest way is just echo 'JOIN';
or you can use a form with hidden input and submit button.
BUT
Your code is really a mess, try to make your code more maintainable and readable. And do NOT use any mysql_* functions, they are deprecated.
Read more about PDO:
http://php.net/manual/en/book.pdo.php
http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/
I am working in a project where i want to show only those products to user which are selected by admin from database. Actualy i want to set the approval 1 or 0 in database when admin check or unchecked that checkbox.
jobs.php
$(document).ready(function(){
$('input.check').click(function(){
if($("input.check").is(':checked'))
{
$id = $(this).attr("id");
$.post("handle.php",{action:"checked",id:$id},function(data){
alert("Peoduct is set to display...");
});
}
else
{
alert("unchecked");
$id = $(this).attr("id");
$.post("handle.php",{action:"unchecked",id:$id},function(data){
alert("Peoduct is un-set to display...");
});
}
});
});
<?php
$dbqry = mysql_query("select * from job_category");
echo "<table width='50%', border='2'>
<tr>
<th>Catergory ID</th>
<th>Category Name</th>
<th>Remove</th>
<th>Update</th>
<th>Approval</th>
</tr>";
if($dbqry)
{
while($row = mysql_fetch_array($dbqry))
{
echo "<tr>";
echo "<td align='center'>" . $row['c_id'] . "</td>";
echo "<td align='center'>" . $row['cat_name'] ."</td>";
$cid = $row['c_id'];
$aprv = $row['approval'];
echo "<td align='center'><a href='remove.php?action=cat_remove&cid=$cid'>Remove</a></td>";
echo "<td align='center'>
<a href='Update-form.php?action=cat_update&cid=$cid'>Update</a></td>";
?>
<td align="center">
<input type='checkbox' name='approval' value='approval' id ="<? echo $cid; ?>" class="check"/>
</td>
</tr>
<?
}
echo "</table>";
echo '<br/>';
echo "<a href='add.php?action=cat_add'>Add New Category</a>";
}
else
{
die(mysql_error());
}
?>`
handle.php
`<?php
include 'include/connection.php';
$action = $_POST['action'];
$id = $_POST['id'];
//echo $action;
if($action == "checked")
{
$query = "update job_category set approval=1 where c_id=$id";
$result = mysql_query($query);
if(!$result)
{
echo die(mysql_error());
}
}
else if($action == "unchecked")
{
$query = "update job_category set approval=0 where c_id=$id";
$result = mysql_query($query);
if(!$result)
{
echo die(mysql_error());
}
}
?>`
Its working but when i refresh the page or seletc the URL and press enter then all the checked data appears unchecked even after that it does not change value of approval from 1 to 0 in database, but still it make me confuse about which items are checked or unchecked. Any suggestion will be appreciated.
modify checkbox line to show checked if approval=1 in database... try this
<input type='checkbox' name='approval' value='approval' <?php if($row["approval"]==1){ echo "checked=\"checked\"";}) ?> id ="<? echo $cid; ?>" class="check"/>
html
<input type='checkbox' name='approval' value='approval' <?php echo $row["approval"]?"checked=\"checked\"":'';?> id ="<? echo $cid; ?>" class="check"/>
then add js
$(function(){
$('input[type=checkbox]').each(function(){
if($(this).attr('checked') && $(this).attr('checked')=='checked'){
$(this).attr('checked', true);
}else{
$(this).attr('checked', false);
}
})
})
and
if($("input.check").is(':checked'))
to
if($(this).is(':checked'))
I'm a novice at this and I just lately dug into the code... I'm having hard time understanding why this doesn't work:
I added a button in the search results so it would delete the certain data field but it doesn't do it.
What am I missing out here?
<?php //deleting
isset($_GET['action']) ? $action=$_GET['action'] : $action="";
if($action=='delete'){
$id=$_REQUEST['id'];
$query=mysql_query("set names 'utf8'");
$query = mysql_query("DELETE FROM norse5_proov WHERE id='$id'") or die(mysql_error());
if($query){
echo "<div id='dain'><br><br><br><br><br><br><br><br><br><br>Andmed kustutatud.</div>";
}
}
?>
<?php //searching
mysql_query ("set character_set_results='utf8'");
if($_SERVER['REQUEST_METHOD'] == "POST"){
$query = "SELECT * FROM norse5_proov WHERE 1=1 ";
if(!empty($_POST["osakond"])){
$query .= " AND osakond LIKE '%".mysql_real_escape_string($_POST["osakond"])."%'";
}
if(!empty($_POST["soetusaasta"])){
$query .= " AND soetusaasta LIKE '%".mysql_real_escape_string($_POST["soetusaasta"])."%'";
}
if(!empty($_POST["it_number"])){
$query .= " AND it_number LIKE '%".mysql_real_escape_string($_POST["it_number"])."%'";
}
if(!empty($_POST["tooteruhm"])){
$query .= " AND tooteruhm LIKE '%".mysql_real_escape_string($_POST["tooteruhm"])."%'";
}
if(!empty($_POST["mudeli_nimetus"])){
$query .= " AND mudeli_nimetus LIKE '%".mysql_real_escape_string($_POST["mudeli_nimetus"])."%'";
}
if(!empty($_POST["sn"])){
$query .= " AND sn LIKE '%".mysql_real_escape_string($_POST["sn"])."%'";
}
if(!empty($_POST["riigivara_nr"])){
$query .= " AND riigivara_nr LIKE '%".mysql_real_escape_string($_POST["riigivara_nr"])."%'";
}
if(!empty($_POST["inventaari_nr"])){
$query .= " AND inventaari_nr LIKE '%".mysql_real_escape_string($_POST["inventaari_nr"])."%'";
}
if(!empty($_POST["maja"])){
$query .= " AND maja LIKE '%".mysql_real_escape_string($_POST["maja"])."%'";
}
if(!empty($_POST["ruum"])){
$query .= " AND ruum LIKE '%".mysql_real_escape_string($_POST["ruum"])."%'";
}
if(!empty($_POST["vastutaja"])){
$query .= " AND vastutaja LIKE '%".mysql_real_escape_string($_POST["vastutaja"])."%'";
}
if(!empty($_POST["markus"])){
$query .= " AND markus LIKE '%".mysql_real_escape_string($_POST["markus"])."%'";
}
if(!empty($_POST["id"])){
$query .= " AND id LIKE '%".mysql_real_escape_string($_POST["id"])."%'";
}
?>
<table id="tablk">
<tr>
<th width="80">Osakond</th>
<th width="80">Soetusaasta</th>
<th width="80">IT Number</th>
<th width="80">Tooterühm</th>
<th width="80">Mudeli nimetus</th>
<th width="80">SN</th>
<th width="80">Riigivara nr</th>
<th width="80">Inventaari nr</th>
<th width="80">Maja</th>
<th width="80">Ruum</th>
<th width="80">Vastutaja</th>
<th width="80">Märkus</th>
<th width="80">ID</th>
<th width="80">Tegevus</th>
</tr>
<?php
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>".$row["osakond"]."</td>";
echo "<td>".$row["soetusaasta"]."</td>";
echo "<td>".$row["it_number"]."</td>";
echo "<td>".$row["tooteruhm"]."</td>";
echo "<td>".$row["mudeli_nimetus"]."</td>";
echo "<td>".$row["sn"]."</td>";
echo "<td>".$row["riigivara_nr"]."</td>";
echo "<td>".$row["inventaari_nr"]."</td>";
echo "<td>".$row["maja"]."</td>";
echo "<td>".$row["ruum"]."</td>";
echo "<td>".$row["vastutaja"]."</td>";
echo "<td>".$row["markus"]."</td>";
echo "<td>".$row["id"]."</td>";
echo "<td>";
echo "<button onclick='delete_user( {id} )'>Kustuta</button>";
echo "<form method='post' action='edit.php?id=<?php echo ".$row["id"]."; ?>'><input type='submit' value='Muuda'>";
echo "</td>";
echo "</tr>";
}
mysql_free_result($result);
?>
</table>
<?php
}
?>
This line:
echo "<button onclick='delete_user( {id} )'>Kustuta</button>";
creates a button and calls delete_user function, but it is not PHP function but Javascript. You probably did not define this function. Secondly the problem might be in {id}, perhaps you should have written delete_user(".$row["id"].").
I suppose you have to create a button that will submit form that is for deletion. You may want to have two forms, one that is for editing (you have it in the next line), the other for deletion.
Instead of the line I cited use:
echo "<form method='post' action='edit.php?action=delete&id=".$row["id"]."'><input type='submit' value='Muuda'>";
echo "<form method='post' action='edit.php?id=<?php echo ".$row["id"]."; ?>
The above line is opening a PHP tag within a PHP string.
try
echo "<button onclick='delete_user(".$row[id].")'>Kustuta</button>";
echo "<form method='post' action='edit.php?action=delete&id=<?php echo ".$row["id"]."; ?>'><input type='submit' value='Muuda'>";
<?php
require 'database.php';
$query = "SELECT id, date, ponumber FROM so";
$result = $mysqli->query($query) or die(mysqli_error($mysqli));
if ($result) {
echo "<form method='post' action='delete.php'>";
echo "<table cellspacing='0' cellpadding='15' border='1'>
<th >DELETE</th>
<th >VIEW</th>
<th >ID</th>
<th >DATE</th>
<th >PO NUMBER</th>";
while ($row = $result->fetch_object()) {
$date = $row->date ;
$ponumber = $row->ponumber;
$id = $row->id;
//put each record into a new table row with a checkbox
echo "<tr>
<td>
<input type='checkbox' name='checkbox[]' id='checkbox[]' value=$id />
</td>
<td>
$id
</td>
<td>
view
</td>
<td>
$date
</td>
<td>
$ponumber
</td>
</tr>";
}
echo "</table><p><input id='delete' type='submit' class='button' name='delete'
value='Delete Selected Items'/></p></form>";}
?>
i have a sort of an online order form which enable the sales rep to input sales order,
i have done the insert and delete using the code above now i want every row to be a hyperlink so that when they click view it will display only row that has been clicked, in my code above if you click :view" all the detail will display, how can i display only the row that i will click will display the detail of the record!
you need to pass the id in the url and you need to read it if it's there.
e.g.
<?php
require 'database.php';
$query = "SELECT id, date, ponumber FROM so";
/* Edit 1 */
if (!empty($_GET['id'])) {
$query .= " WHERE id = " . mysql_real_escape_string($_GET['id']);
}
/* Edit 1 end */
$result = $mysqli->query($query) or die(mysqli_error($mysqli));
if($result) {
echo "<form method='post' action='delete.php'>";
echo "<table cellspacing='0' cellpadding='15' border='1'>
<th >DELETE</th><th >VIEW</th><th >ID</th><th >DATE</th><th >PO NUMBER</th>";
while ($row = $result->fetch_object()) {
$date = $row->date ;
$ponumber = $row->ponumber;
$id = $row->id;
//put each record into a new table row with a checkbox
echo "<tr>
<td><input type='checkbox' name='checkbox[]' id='checkbox[]' value=$id /></td>
<td>$id</td>
<td>";
/* Edit 2 */
echo "<a href='view.php?id=$id'>view</a>";
/* Edit 2 End */
echo "</td>
<td>$date</td>
<td>$ponumber</td></tr>";
}
echo "</table><p><input id='delete' type='submit' class='button' name='delete' value='Delete Selected Items'/></p></form>";}
?>
A style suggestion:
Don't do/stop doing this:
echo "<form method='post' action='delete.php'>";
echo ...
while
Where what you are echoing is a static string. Instead, do:
?>
<form method='post' action='delete.php'>
...
<?php
while
it's simply easier to read and maintain.