how to display the row from database with check box using php - php

<?php
$usn=$_GET['usn'];
$con=mysqli_connect('localhost','root','','library');
$sql="select count(*) from book_fine where usn='$usn'";
$res=mysqli_query($con,$sql);
$row=mysqli_fetch_array($res);
if($row[0]>0)
{
$sql="select * from book_fine where usn='$usn'";
$res=mysqli_query($con,$sql);
echo '<html><form><table class="table table-bordered">
<tr>
<th><input type="checkbox" name="check_all" id="check_all" value=""/></th>
<th>USN</th>
<th>Trans No</th>
<th>Acc No</th>
<th>category</th>
<th>description</th>
<th>issue_date</th>
<th>due_date</th>
<th>renewed</th>
<th>fine</th>
</tr>
';
while($row=mysqli_fetch_array($res)){
?>
<tr><td><input type="checkbox" name="selected_id[]" class="checkbox" value="<?php echo $usn; ?>"/></td>
<?php echo" <td>".$row[0]."</td>
<td>".$row[1]."</td>
<td>".$row[2]."</td>
<td>".$row[3]."</td>
<td>".$row[4]."</td>
<td>".$row[5]."</td>
<td>".$row[6]."</td>
<td>".$row[7]."</td>
<td>".$row[8]."</td>
</tr></form></html>";
}
echo "</table>";
}else{
echo "string";
}
?>

Related

date filter not wroking for mysql in php

Table name :- add_user
data is inserting in it, there is a column due_date storing date in (dd-mm-yyyy) format
now i want to create a filter for due_date. But my code is not working. When i'm running the code it is showing all data, it is not filtering it.
here is my code
<form class="form-inline" method="post" action="">
<label> <b>From Date :  </b></label>
<input type="date" name="s_date" class="form-control"> 
<input type="date" name="e_date" class="form-control">
<button type="submit" name="search" class="btn btn-success">Search</button>
</form>
<?php
error_reporting(0);
include_once "config2.php";
if(count($_POST)>0) {
$s_date=date("dd-mm-yyyy", strtotime($_POST['s_date']));
$e_date=date("dd-mm-yyyy", strtotime($_POST['e_date']));
$result = mysqli_query($conn,"SELECT * FROM add_user WHERE due_date BETWEEN '$s_date' AND '$e_date'");
}
?>
<center>
<table class='table table-bordered'>
<thead class="thead-dark">
<tr>
<th>Action</th>
<th>Pet Photo</th>
<th>Owner</th>
<th>Mobile Number</th>
<th>Category</th>
<th>Pet Id</th>
<th>Pet Name</th>
<th>Address</th>
</tr>
<?php
$i=0;
while($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><button class="btn btn-info">View</button></td>
<td><img src="/pet_img/<?php echo $row["signature"]; ?>"width="60px"height="80px"> </td>
<td><img src="/pet_img/<?php echo $row["photo"]; ?>"width="60px"height="80px"> <br><b> <?php echo $row["name"]; ?> </td>
<td><?php echo $row["mobile"]; ?></td>
<td><?php echo $row["type"]; ?></td>
<td><b><font color="green"><?php echo $row["pet_id"]; ?></font></b></td>
<td><?php echo $row["pet_name"]; ?></td>
<td><?php echo $row["add1"]; ?> <?php echo $row["add2"]; ?> <?php echo $row["add3"]; ?> <?php echo $row["pin"]; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
</body>
</html>
Your column data type needs to be either timestamp or date/datetime. You can't compare date strings in this format.

instant delete when the button is cliked

im trying to delete from a datatable when i click the remove button the data will be removed for a quick action in the admin side but my code dose not work i tried to fix it but i don't see any problem in the code here is my code
<div class="table-responsive">
<table id="datas" class="table table-striped table-bordered fixed" style="width:100%">
<thead style="color:black;" >
<th>id</th>
<th>Company Name</th>
<th>Product Name</th>
<th>Weight</th>
<th>Price Per Gram</th>
<th>Quantity</th>
<th>Type</th>
<th>Category</th>
<th>Product Price</th>
<th>Image</th>
<th>Total Price</th>
<th class="text-center">Actions</th>
</thead>
<?php
$get = mysqli_query($conn,"SELECT * FROM stock;");
?>
<tbody>
<?php
while ($row=mysqli_fetch_array($get)) {
$id=$row['id'];
$company=$row['company_name'];
$name=$row['product_name'];
$weight=$row['weight'];
$price_per_gram=$row['price_per_gram'];
$quantity=$row['quantity'];
$type=$row['type'];
$category=$row['category'];
$price=$row['product_price'];
$img=$row['img'];
$total=$row['total_price'];
?>
<tr>
<td ><?php echo $id;?></td>
<td><?php echo $company;?></td>
<td><?php echo $name;?></td>
<td><?php echo $weight;?> g</td>
<td><?php echo $price_per_gram;?> $</td>
<td><?php echo $quantity;?></td>
<td><?php echo $type;?></td>
<td><?php echo $category;?></td>
<td><?php echo $price;?></td>
<td>
<img src="product_img/<?php echo $img; ?>" style="height:5rem;width:5rem;border-radius:10px;">
</td>
<td><?php echo $total;?></td>
<td style="width: 20px"> Edit
<button class="btn btn-danger" name="delete" type="submit" value="<?php echo "$id" ?>">Delete</button> </td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
if (isset($_POST['delete'])) {
$delete = mysqli_query($conn,"DELETE FROM stock WHERE id= ".$_POST['delete']." ");
header("location:viewstcok.php");
} ?>
i give the delete button a value when clicked so it will delete with that value but it did not seems to work can any one help me
you have to placed table inside <form></form> tag
<div class="table-responsive">
<form>
<table id="datas" class="table table-striped table-bordered fixed" style="width:100%">
<thead style="color:black;" >
<th>id</th>
<th>Company Name</th>
<th>Product Name</th>
<th>Weight</th>
<th>Price Per Gram</th>
<th>Quantity</th>
<th>Type</th>
<th>Category</th>
<th>Product Price</th>
<th>Image</th>
<th>Total Price</th>
<th class="text-center">Actions</th>
</thead>
<?php
$get = mysqli_query($conn,"SELECT * FROM stock;");
?>
<tbody>
<?php
while ($row=mysqli_fetch_array($get)) {
$id=$row['id'];
$company=$row['company_name'];
$name=$row['product_name'];
$weight=$row['weight'];
$price_per_gram=$row['price_per_gram'];
$quantity=$row['quantity'];
$type=$row['type'];
$category=$row['category'];
$price=$row['product_price'];
$img=$row['img'];
$total=$row['total_price'];
?>
<tr>
<td ><?php echo $id;?></td>
<td><?php echo $company;?></td>
<td><?php echo $name;?></td>
<td><?php echo $weight;?> g</td>
<td><?php echo $price_per_gram;?> $</td>
<td><?php echo $quantity;?></td>
<td><?php echo $type;?></td>
<td><?php echo $category;?></td>
<td><?php echo $price;?></td>
<td>
<img src="product_img/<?php echo $img; ?>" style="height:5rem;width:5rem;border-radius:10px;">
</td>
<td><?php echo $total;?></td>
<td style="width: 20px"> Edit
<button class="btn btn-danger" name="delete" type="submit" value="<?php echo "$id" ?>">Delete</button> </td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
<?php
if (isset($_POST['delete'])) {
$delete = mysqli_query($conn,"DELETE FROM stock WHERE id= ".$_POST['delete']." ");
header("location:viewstcok.php");
} ?>

I want to delete multiple images from source folder through PHP but the code for deleting the multiple images from the folder is not working

<?php include("header.php"); ?>
<?php
if (#$_POST['delete']=="Delete"){
$count=count($_POST['delbx']);
for($i=0;$i<$count;$i++){
$delete = "DELETE FROM admin WHERE a_id='".$_POST['delbx'][$i]."'";
$resulty = mysqli_query($conn, $delete) or die(mysql_error());
$select_delete = "SELECT `a_image` FROM admin WHERE a_id='".$_POST['delbx'][$i]."'";
$resultrowdy = $conn->query($select_delete);
$rowdy = $resultrowdy->fetch_assoc();
$path="admin/".$rowdy['a_image'];
echo $path;
unlink($path);
echo '<script>window.location="view_user.php"</script>';
}
} ?>
<div class="table-responsive">
<table class="table">
<caption>All Users</caption>
<?php
$sql = "SELECT a_id, a_name, a_phone, a_password, a_role, a_mail, a_image FROM admin";
$result = $conn->query($sql);
if ($result->num_rows > 0) {?>
<thead>
<tr>
<th><form action="view_user.php" method="post"><input name="delete" type="submit" id="delete" value="Delete"></th><th>S. No.</th> <th>Name</th> <th>Phone No.</th> <th>Mail Id</th> <th>Role</th> <th>Password</th> <th>Image</th>
</tr>
</thead>
<?php
while($row = $result->fetch_assoc()) { ?>
<tbody>
<tr>
<th scope="row">
<?php echo $row["a_id"]; ?>
</th>
<td align="center" bgcolor="#FFFFFF">
<input name="delbx[]" type="checkbox" id="delbx[]" value="<?php echo $row["a_id"]; ?>" />
</td>
<td>
<?php echo $row["a_name"]; ?>
</td>
<td>
<?php echo $row["a_phone"]; ?>
</td>
<td>
<?php echo $row["a_mail"]; ?>
</td>
<td>
<?php echo $row["a_role"]; ?>
</td>
<td>
<?php echo $row["a_password"]; ?>
</td>
<td>
<img src="admin/<?php echo $row["a_image"]; ?>" width="60" height="40">
</td>
<th>
Edit
</th>
</tr>
</tbody>
<?php
}
} else {
echo "0 results";
}?>
</table>
</form>
</div>
<?php include("footer.php"); ?>
The code I mention is not deleting the multiple images from the source folder but deleting the multiple data from database whereas I am trying to delete images from the source folder along with data please help thanks in advance
One of the problem is you are deleting the row and trying to select image column from the deleted row.. dont use user supplied variables directly in your query
your code should be
for($i=0;$i<$count;$i++){
$select_delete = "SELECT `a_image` FROM admin WHERE a_id='".$_POST['delbx'][$i]."'";
$resultrowdy = $conn->query($select_delete);
$rowdy = $resultrowdy->fetch_assoc();
$delete = "DELETE FROM admin WHERE a_id='".$_POST['delbx'][$i]."'";
if(mysqli_query($conn, $delete)){
$path="admin/".$rowdy['a_image'];
unlink($path);
echo '<script>window.location="view_user.php"</script>';
}
}

How to only shown one table after clicking search button?

I have a 2 tables like this when I search the member name.
link :
I wanted the search result to be shown only after search.
my code:
<div id = "subtitle">
View Members
</div>
<div id = "searchbox">
<form method="post">
<center><input type="text" maxlength="100" required placeholder="Enter Full Name" name ="search" autocomplete="off" value="">
<input type="submit" name="btn" value="SEARCH NOW!"></p></center>
</form>
</div>
<?php
if(isset($_POST["btn"]))
{
$search = $_POST["search"];
$sql = "select * from member where Member_Name like '$search%' ";
$result = mysqli_query($conn,$sql);
$rowcount = mysqli_num_rows($result);
if($rowcount==0)
echo "Sorry ,no records found!";
else
{
?>
<center><table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Member ID</th>
<th>Member Name</th>
<th>Actions</th>
</tr>
<?php
while($row=mysqli_fetch_assoc($result)) //display
{
?> <tr>
<td></td>
<td><?php echo $row["Member_ID"]?></td>
<td><?php echo $row["Member_Name"]?></td>
<td><img src=../Images/ViewFile.png height=37px title=View>
<img src=../Images/edit.png height=37px title=Edit>
</td>
</tr>
</table>
</center>
<?php
}
}
}
?>
<center><table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Member ID</th>
<th>Member Name</th>
<th>Actions</th>
</tr>
<?php
$sql = "select * from legoclub_guesthouse.member";
$result = mysqli_query($conn,$sql);
$rowcount= mysqli_num_rows($result);
while($row=mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td></td>";
echo "<td>$row[Member_ID]</td>";
echo "<td>$row[Member_Name]</td>";
echo "<td><img src=../Images/ViewFile.png height=37px title=View>
<img src=../Images/edit.png height=37px title=Edit>
</td>";
echo "</tr>";
}
?>
</table><center>
</div>
Please include the php file for me too!
To do it in easiest way just try to use this code:
<div id = "subtitle">
View Members
</div>
<div id = "searchbox">
<form method="post">
<center><input type="text" maxlength="100" required placeholder="Enter Full Name" name ="search" autocomplete="off" value="">
<input type="submit" name="btn" value="SEARCH NOW!"></p></center>
</form>
</div>
<?php
if(isset($_POST["btn"]))
{
$search = $_POST["search"];
$sql = "select * from member where Member_Name like '$search%' ";
$result = mysqli_query($conn,$sql);
$rowcount = mysqli_num_rows($result);
if($rowcount==0)
echo "Sorry ,no records found!";
else
{
?>
<center><table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Member ID</th>
<th>Member Name</th>
<th>Actions</th>
</tr>
<?php
while($row=mysqli_fetch_assoc($result)) //display
{
?> <tr>
<td></td>
<td><?php echo $row["Member_ID"]?></td>
<td><?php echo $row["Member_Name"]?></td>
<td><img src=../Images/ViewFile.png height=37px title=View>
<img src=../Images/edit.png height=37px title=Edit>
</td>
</tr>
<?php
}
$sql = "select * from legoclub_guesthouse.member";
$result = mysqli_query($conn,$sql);
$rowcount= mysqli_num_rows($result);
while($row=mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td></td>";
echo "<td>$row[Member_ID]</td>";
echo "<td>$row[Member_Name]</td>";
echo "<td><img src=../Images/ViewFile.png height=37px title=View>
<img src=../Images/edit.png height=37px title=Edit>
</td>";
echo "</tr>";
}
?>
</table>
</center>
<?php
}
}
?>
</div>
But I would recommend you to use SQL UNION Operator.
It will make your life easy for these type of problems

sort data by field heading php mysql

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

Categories