I am very new to PHP and HTML. I am trying to fetch the row value from input form data, but i am unable to fetch the data.
Below is my code.
HTML:
<form id="main" action="test.php" method="post" enctype="multipart/form-data" >
<div class="row">
<div class="col-md-12">
<label for="model" style="font-size: 15px"> Model </label><br>
<input type="text" id="tags" name="model" placeholder="Type Your Model Number" >
</div>
</div>
<div class="row">
<div class="col-md-12">
<button type="submit" id="button" name="submit1" />SUBMIT</button>
</div>
</div>
</form>
</html>
PHP CODE:
<?php
if(isset($_POST['submit']))
{
// id to search
$model = $_POST['model'];
// connect to mysql
$connect = mysqli_connect("localhost", "root", "","test");
// mysql search query
$query = "SELECT `offer`, `amount` FROM `offer`";
$result = mysqli_query($connect, $query);
// if id exist
// show data in inputs
if(mysqli_num_rows($result) > 0)
{
while ($row = mysqli_fetch_array($result))
{
$offer = $row['offer'];
$amount = $row['amount'];
}}
if($model){
echo "
<form method='post' action=''>
<div class='col-md-5'>
$offer
</div>
<div class='col-md-5'>
INR $amount/-
</div>
</div></form>";
else {
$offer = "";
$amount = "";
$offer2 = "";
$amount2 = "";
}
mysqli_free_result($result);
mysqli_close($connect);}
else{
$offer = "";
$amount = "";
$offer2 = "";
$amount2 = "";
}
?>
Also, please note that the model is alphanumeric. Offer would be Headset and amount would be 100. I request to help me on this.
First of all we don't know what your error is and second you haven't included all your code. However, for PHP use following code
<?php
$mysqli = new mysqli("localhost", "root", "", "test") or die($mysqli->error);
$select = $mysqli->query("SELECT * from offer") or die($mysqli->error);
if($select->num_rows){
while($row = $select->fetch_array(MYSQLI_ASSOC)){
$amount = $row['amount'];
$offer= $row['offer'];
}
}
?>
You have used input and button but i don't see any form tags in HTML
You have to pass the $model in your query and do that to show the results:
echo "<form method='post' action=''>";
while ($row = mysqli_fetch_array($result))
{
echo " <div class='col-md-5'>
".$row['offer']."
</div>
<div class='col-md-5'>
INR ".$row['amount']."-
</div> ";
}
echo "</form>";
Related
I am coding a website for an online university portal where I have a programs/courses page in which I am displaying the programs/courses on the page using data from the database in a PHP while-loop I have the enroll buttons also being displayed in that same while loop. but I'm having a bit of difficulty submitting the enroll buttons as when I click one of them all of them get submitted.
can anyone please let me know what I'm doing wrong here or if I have to use any javascript in this case!
<?php
session_start();
$con = mysqli_connect('localhost', 'root', '');
mysqli_select_db($con, 'htdatabase');
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
$id = $_SESSION['userID'];
$sql = "SELECT * FROM programs";
$result = $con->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$i = '';
$progID = $row["progID"];
$name = $row["progName"];
$halfTime = $row["halfTDuration"];
$fullTime = $row["fullTDuration"];
$fee = $row["fee"];
$descrip = $row["description"];
$stringname = strval($name);
$spaceRemoved = str_replace(' ', '', $stringname);
?>
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<?php echo "<button class='btn btn-link' type='button' data-toggle='collapse' data-target='#$spaceRemoved' aria-expanded='false' aria-controls='$spaceRemoved'> $name </button>"; ?>
</h5>
</div>
<?php echo "<div id='$spaceRemoved' class='collapse' aria-labelledby='headingOne' data-parent='#accordionExample'>"; ?>
<div>
<div class="ccard-body col-md-9">
<h6><?php echo $descrip; ?></h6>
<hr>
<h5>Duration:</h5>
<h6>Full time: <?php echo $fullTime; ?></h6>
<h6>Half time: <?php echo $halfTime; echo $i; ?></h6>
<hr>
<h5 style="display: inline-block;">Estimated fees: $</h5><h5 style="display: inline-block;"><?php echo $fee ?></h5>
</div>
<form action="programs.php" method="post">
<div id="enroll" class="col-md-3">
<?php
$sql1 = "SELECT * FROM userprograms WHERE userID = '$id' AND progID = '$progID'";
$result1 = $con->query($sql1);
if ($result1->num_rows > 0) {
echo '<div id="enrolled" name="enrolled">ENROLLED</div>';
} else {
if (isset($_POST["enroll"])) {
$enrollqry = "insert into userprograms (userID, progID) values ('$id' , '$progID')";
mysqli_query($con, $enrollqry);
}
echo "<button name='enroll'type='submit'>ENROLL</button>";
}
?>
</div>
</form>
</div>
</div>
<?php
}
} ?>
You can specify a value for the button. like
<button name='enroll' value="<?php echo $program_id?>" type='submit'>ENROLL</button>
Then when checking for $_POST['enroll'] check the value and also validate it before entry to db.
After clicking the submit button a browser will send a POST request to programs.php with a form data, that includes values of input & button tags.
<input type="submit" name="course1" value="42">Subscribe</input>
<input type="text" name="first_name" placeholder="Your name"/>
Will send
course1=42
first_name=...
So you should either give a unique name to each submit button to be able to distinguish them on the server-side, or set up distinct values, as #mohamed-jailam mentioned above.
I made a table in php and wanted to show the Id's in the dropdown select menu by making a separate file for php. So the code in main file is:
<?php include "functions.php";?>
<form action="login_update.php" method="post">
<div class="form-group">
<label for="username">username</label>
<input type="text" name="username" class="form-control">
</div>
<div class="form-group">
<label for="password">password</label>
<input type="password" name="password" class="form-control">
</div>
<div class="form-group">
<select name="id" id="">
<?php
showAllData();
echo "<br>"."askfkldfjl;adfafladfdf";
?>
</select>
</div>
<input class="btn btn-primary" type="submit" name="submit" value="update">
</form>
The code of functions.php is :
<?php
function showAllData(){
$connection = mysqli_connect('localhost','root','****','loginapp');
if($connection){
echo "We are connected. a=".$a."<br>";
}else{
die("Database connection failed");
}
$query = "SELECT * FROM users";
$result = mysqli_query($connection,$query);
if($result){
echo("<br>"." <b><h6>We are successful</h6></b>");
}
else {
die("Query FAILED" . mysqli_error());
}
while($row = mysqli_fetch_assoc($result)) {
$id = $row["id"];
echo"<option value='$id'>$id</option>";
}
}
?>
The expected output was :
But the output is:
So the top two lines in the above screenshot are not printing.
These lines are shown in the INSPECT ELEMENT in chrome.
I forgot to mention the echo command:
echo "<br>"."askfkldfjl;adfafladfdf";
below show all data is also not working.
You made a mistake.
Actually you wrote a code in selectbox and you dont add option so thats why it is not show in html
So write a code like below code so its show in select box as option.
<div class="form-group">
<select name="id" id="">
<option> <?php
showAllData();
echo "<br>"."askfkldfjl;adfafladfdf";
?></option>
</select>
</div>
And If you want to show option from showAllData(); function, the you have return the html.
For this update your showAllData(); function with below code:
function showAllData(){
$options="";
$connection = mysqli_connect('localhost','root','****','loginapp');
if($connection){
echo "We are connected. a=".$a."<br>";
}else{
die("Database connection failed");
}
$query = "SELECT * FROM users";
$result = mysqli_query($connection,$query);
if($result){
echo("<br>"." <b><h6>We are successful</h6></b>");
}
else {
die("Query FAILED" . mysqli_error());
}
while($row = mysqli_fetch_assoc($result)) {
$id = $row["id"];
$options.="<option value='$id'>$id</option>";
}
return $options;
}
Move the PHP function showAllData() before the HTML <select> element.
Because the <select> element awaits for an <option> element, but all another text will not be visible on page.
E.g.:
<div class="form-group">
<?php showAllData(); ?>
</div>
<?php
function showAllData(){
$connection = mysqli_connect('localhost','root','****','loginapp');
if($connection){
echo "We are connected. a=".$a."<br>";
}else{
die("Database connection failed");
}
$query = "SELECT * FROM users";
$result = mysqli_query($connection,$query);
if($result){
echo("<br>"." <b><h6>We are successful</h6></b>");
}
else {
die("Query FAILED" . mysqli_error());
}
echo '<select name="id" id="">';
while($row = mysqli_fetch_assoc($result)) {
$id = $row["id"];
echo"<option value='$id'>$id</option>";
}
echo "</select>";
}
?>
Your code is mixed up.
You can use below code. Create an array which gives you values which you needs to show in select.
<?php
function showAllData(){
$idArr = array('msg'=>'','data'=>'','status'=>0);
$connection = mysqli_connect('localhost','root','****','loginapp');
if($connection){
$idArr['msg'] = "We are connected";
$idArr['status'] = 1;
}else{
$idArr['msg'] = "Database connection failed";
$idArr['status'] = 0;
}
if($idArr['status'] == 1){
$query = "SELECT * FROM users";
$result = mysqli_query($connection,$query);
if($result){
$idArr['msg'] = "We are successful";
$idArr['status'] = 1;
}else {
$idArr['msg'] = "Query FAILED" . mysqli_error();
$idArr['status'] = 0;
}
if($idArr['status'] == 1){
while($row = mysqli_fetch_assoc($result)) {
$idArr['data'][] = $row["section_id"];
}
}
}
return $idArr;
}
$idArr = showAllData();
?>
<?php
if(!empty($idArr['data'])){
echo "We are connected<br>";
echo("<br>"." <b><h6>We are successful</h6></b>");
?>
<form action="login_update.php" method="post">
<div class="form-group">
<label for="username">username</label>
<input type="text" name="username" class="form-control">
</div>
<div class="form-group">
<label for="password">password</label>
<input type="password" name="password" class="form-control">
</div>
<div class="form-group">
<select name="id" id="">
<option value="0">--Select--</option>
<?php
foreach ($idArr['data'] as $key => $value) {
echo"<option value='$value'>$value</option>";
}
?>
</select>
</div>
<input class="btn btn-primary" type="submit" name="submit" value="update">
</form>
<?php }else{
echo $idArr['msg'];
}
?>
Why you are putting <br> inside the select tag? select tag only accept the options tag under it, so please remove br tag and all extra strings inside the select tag. and you should echo the message above the select tag if you want to show your users.
Thanks
This is my first post in this forum, despite being a devoted follower for years now.
I have built a simple system that registers lot numbers and their locations within a MySQL database through a PHP form.
Then i have this other form called "Errata Corrige" that I use to find and edit eventual mistaken entries.
It's search criteria is an (UNSIGNED INT UNIQUE) value named "lotto" and everything works (worked) like a charm under this circumstances.
Now the thing got a little tricky.
I found out that lot numbers (lotto) for work purposes are not always unique values, there might be more than one entry with the same number.
No problem making the "Insert" form or various counters work under this new circumstances, but it got really tricky within the EDIT functions.
This is my PHP code: `
<?php
$id = "";
$settore = "";
$ubicazione = "";
$numero = "";
$lotto="";
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
// connect to mysql database
try{
$connect = mysqli_connect($host, $user, $password, $database);
} catch (mysqli_sql_exception $ex) {
echo 'Error';
}
// get values from the form
function getPosts()
{
$posts = array();
$posts[0] = $_POST['id'];
$posts[1] = $_POST['settore'];
$posts[2] = $_POST['ubicazione'];
$posts[3] = $_POST['numero'];
$posts[4] = $_POST['lotto'];
return $posts;
}
// Search
if(isset($_POST['search']))
{
$data = getPosts();
$search_Query = "SELECT * FROM mappa WHERE lotto = $data[4]";
$search_Result = mysqli_query($connect, $search_Query);
if($search_Result)
{
if(mysqli_num_rows($search_Result))
{
while($row = mysqli_fetch_array($search_Result))
{
$id = $row['id'];
$settore = $row['settore'];
$ubicazione = $row['ubicazione'];
$numero = $row['numero'];
$lotto = $row ['lotto'];
}
}else{
echo 'Lotto non presente in archivio';
}
}else{
echo 'Error';
}
}
// Insert
if(isset($_POST['insert']))
{
$data = getPosts();
$insert_Query = "INSERT INTO `mappa`(`settore`, `ubicazione`, `numero`, `lotto` ) VALUES ('$data[1]','$data[2]',$data[3], $data[4])";
try{
$insert_Result = mysqli_query($connect, $insert_Query);
if($insert_Result)
{
if(mysqli_affected_rows($connect) > 0)
{
$resInsert = "1 nuovo dato inserito correttamente!";
}else{
$resInsert = "Nessun dato inserito";
}
}
} catch (Exception $ex) {
echo 'Errore '.$ex->getMessage();
}
}
// Edit
if(isset($_POST['update']))
{
$data = getPosts();
$update_Query = "UPDATE `mappa` SET `settore`='$data[1]',`ubicazione`='$data[2]',`numero`=$data[3],`lotto`=$data[4] WHERE `id` = $data[0]";
try{
$update_Result = mysqli_query($connect, $update_Query);
if($update_Result)
{
if(mysqli_affected_rows($connect) > 0)
{
$resAgg = "1 dato aggiornato correttamente!";
}else{
$resAgg = "Nessun dato aggiornato!";
}
}
} catch (Exception $ex) {
echo 'Error Update '.$ex->getMessage();
}
} ?>
`
HTML:
<form action="mod.php" method="post" class="form-horizontal form-bordered" style="text-align:center">
<div class="form-group has-error" style="padding-top:30px">
<label class="col-xs-3 control-label" for="state-normal">ID</label>
<div class="col-lg-3">
<input type="text" name="id" placeholder="ID" class="form-control" value="<?php echo $id;?>"> </div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="state-normal">Settore</label>
<div class="col-md-6">
<input type="text" name="settore" placeholder="Settore" class="form-control" value="<?php echo $settore;?>"> </div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="state-normal">Ubicazione</label>
<div class="col-md-6">
<input type="text" name="ubicazione" placeholder="Ubicazione" class="form-control" value="<?php echo $ubicazione;?>"> </div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="state-normal">Numero</label>
<div class="col-md-6">
<input type="text" name="numero" placeholder="Numero" class="form-control" value="<?php echo $numero;?>"> </div>
</div>
<div class="form-group has-success">
<label class="col-md-3 control-label" for="state-normal">Lotto</label>
<div class="col-md-6">
<input type="text" name="lotto" placeholder="Lotto" class="form-control" value="<?php echo $lotto;?>"> </div>
</div>
<div style="padding-top:16px">
<!-- Insert-->
<button type="submit" name="insert" value="Add" class="btn btn-effect-ripple btn-primary">Inserisci</button>
<!-- Update-->
<button type="submit" name="update" value="Update" class="btn btn-effect-ripple btn-info">Aggiorna</button>
<a> </a>
<!-- Search-->
<button type="submit" name="search" value="Find" class="btn btn-effect-ripple btn-success">Cerca</button>
</div>
</form>
While the lot number was unique everything worked like a charm.
Now that there are multiple data with the same lot number the code became obsolete since the "search" function only shows the last (greatest ID) data.
I have tried to work around a loop and tell the function to search every ID where lotto = lotto but it didn't work.
A simple solution would be obviously searching through ID instead of lotto but that is a pretty crapy one, since the user only knows (and is interested in) Lot Numbers not the ID it was assigned during data insertion.
Then I tried to put two php functions into one page, the first that fetches data from Mysql into a PHP dropdown menu, telling it to show every ID that matches the search criteria (lotto):
<?php if (isset($_POST['submitted'])){
include ('../mysql_connect.php'); // connessione al database
$category = 'lotto';
$criteria = $_POST['criteria'];
$query = "SELECT * FROM mappa WHERE $category = '$criteria'";
$result = mysqli_query($dbcon, $query) or die('Impossibile reperire i dati');
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$idTab = $row['id'];
echo "<option>
$idTab </option>";
}
} // FINE if ?>
</select>
Fetching data from MySQL into the dropdown worked just fine, but I got stucked in the syntax trying to use this dropdown as a search criteria for my first function.
Every help would really be appreciated! Thank you in advance for your answers.
You said that lotto is unique. So how come you are able to insert multiple rows with the same lotto?
Remove the unique constraint from the lotto column.
Try the following:
$query = select lotto, group_concat(id) as ID numbers from mappa where lotto = 'user search number' group by lotto;
$result = $conn->query($query);
$rows = $result->num_rows;
$result->data_seek(0); //move to first row (which is the only one)
$row = $result->fetch_array(MYSQLI_NUM); //fetch array
$id_numbers_string = $row[1]; //store the values of the row's second column (which is number 1)
$id_numbers_separated_array = explode(",", $id_numbers_string); //create an array with the values in the string
for($i = 0; $i < count($id_numbers_separated_array); $i++){ //loop through created array
echo "ID: " . $id_numbers_separated_array[$i];
echo "<br>";
}
Also try to run the query in your database management system to see the results.
I'm having a challenge with a mini project I'm working on and have googled for a solution for hours without a headway.
I have a column in my database table whose contents are generated by exploding a previous form inputs(separated by comma in the table). Now I need to get inputs (from users) for these values using textarea in a form. These inputs will be in arrays depending on the number of contents fetched from the db in the first place and then stored in another column in my table. The issue here is that each time I submit the form I get an undefined index notice for the name of the values in the textarea field, which is test-col [].
please see my code below:
<?php
$conn = mysqli_connect('localhost', 'root', '', 'myDb');
$users_id = mysqli_real_escape_string($conn, $_GET['id']);
$res = mysqli_query($conn, "SELECT tests FROM bal WHERE users_id = '$users_id'");
if ($res){
while ($row = mysqli_fetch_array($res)){
$tests = explode(',', $row['tests']);
foreach($tests as $test){
if ($test ==""){
continue;
}
echo '<div class="test-res" style="margin-top:10px;">
<form action="" method="post" role="form" class="form-horizontal">
<div class="form-group">
<label for= "test-col" class="form-label col-md-2">'.$test.' test</label>
<div class="col-md-10">
<textarea class="form-control" rows="3" name="test-col[]" placeholder="Test result"> </textarea>
</div>
</div>
</form>
</div>';
'<br /> <br />';
}
}
}
echo '<form action="" method="post">
<button type="submit" class="btn btn-success col-md-offset-5" name="sub-res">Send Result</button>
</form>';
?>
//to insert textarea values in db
<?php
if(isset($_POST['sub-res'])){
$conn = mysqli_connect('localhost', 'root', '', 'myDb');
foreach ($_POST ['test-col'] as $values){
$test_results = implode("<br>", $values);
}
$ins = mysqli_query($conn, "INSERT INTO bal (results) VALUES
('$test_results') WHERE users_id = '$users_id'");
if (!$ins){
die(mysqli_error());
}
else{
echo '<div class="alert alert-success">Successfully sent</div>';
}
}
?>
You have two forms - one in your while/foreach statement, and then one below. If you're submitting the second form, it won't contain values from the first.
Wrap the while in the form instead;
<form action="" method="post">
<?php
$conn = mysqli_connect('localhost', 'root', '', 'myDb');
$users_id = mysqli_real_escape_string($conn, $_GET['id']);
$res = mysqli_query($conn, "SELECT tests FROM bal WHERE users_id =
'$users_id'");
if ($res){
while ($row = mysqli_fetch_array($res)){
$tests = explode(',', $row['tests']);
foreach($tests as $test){
if ($test =="") {
continue;
}
echo '<div class="test-res" style="margin-top:10px;"><div class="form-group">
<label for= "test-col" class="form-label col-md-2">'.$test.' test</label><div class="col-md-10"><textarea class="form-control" rows="3" name="test-col[]" placeholder="Test result"> </textarea></div></div></div>';
'<br /> <br />' ;
}
}
}
?>
<button type="submit" class="btn btn-success col-md-offset-5" name="sub-res">Send Result</button>
</form>
I can not understand why the application delete the las upload.I am new in php and I hope to help me. Thank you.
Code: HTML
<div class="row">
<div class="col-md-6 col-centered">
<div class="newboxes" id="newboxes3">
<form class="form" method="POST">
<input type="text" id="nmPic" name="nmPic" placeholder="име на снимката" onfocus="this.placeholder = ''" onblur="this.placeholder = 'име на снимката'"></br>
<input type="text" id="price" class="priceFrom" name="priceFrom" placeholder="цена от" onfocus="this.placeholder = ''" onblur="this.placeholder = 'цена от'"></br>
<input type="text" id="price" class="priceTo" name="priceTo" placeholder="цена до" onfocus="this.placeholder = ''" onblur="this.placeholder = 'цена до'"></br>
<select name="picCat" id="picCat">
<option value="" selected disabled>Изберете категория</option>
<option value="Детски">Детски</option>
<option value="Сватби">Сватби</option>
<option value="Рожден ден">Рожден ден</option>
<option value="18+">18+</option>
<option value="Други">Други</option>
</select></br>
<input type="text" id="numPic" name="numPic" placeholder="номер на снимката" onfocus="this.placeholder = ''" onblur="this.placeholder = 'номер на снимката'"></br>
<input type="submit" name="showFilter" value="покажи" />
</form>
</div>
</div>
</div>
Code: php
<div class="row">
<div class="col-md-12 col-centered pic">
<form class='form' method='POST'>
<?php
if (isset($_POST["showFilter"]))
{
$picName = $_POST['nmPic'];
$priceFrom = $_POST['priceFrom'];
$priceTo = $_POST['priceTo'];
$picCat = isset($_POST['picCat']) ? $_POST['picCat'] : '';
$numPic = $_POST['numPic'];
$filter = " SELECT * FROM images WHERE status = '1'";
if ($numPic && !empty($numPic)) {
$filter .= " AND id='$numPic'";
}
if ($picName && !empty($picName)) {
$filter .= " AND img_content='$picName'";
}
if ($picCat && !empty($picCat)) {
$filter .= " AND category='$picCat'";
}
if ($priceTo && !empty($priceTo)) {
$filter .= " AND price < '$priceTo'+1";
}
if ($priceFrom && !empty($priceFrom)) {
$filter .= " AND price > '$priceFrom'";
}
$resFilter = $connect->query($filter);
if ($resFilter->num_rows > 0) {
while($row = mysqli_fetch_array($resFilter))
{
echo "<div class='col-md-3 picture'>
<img class='child-img' src='".$row["picture"]." '/></br>
<div class='number'>
<span class='id'>№ ".$row['id']."</br>
име: ".$row['img_content']."</br> категория: ".$row['category']."</br>
цена: ".$row['price']."лв.</br>
дата: ".$row['time']."ч.</br>
</span>
<input type='hidden' name='del' value=" .$row['id'].">
<input class='btn btn-danger' name='delete' type='submit' value='истрии'/>
</div>
</div>";
}
}
}
?>
</form>
</div>
</div>
<form method="POST">
<?php
if (isset($_POST['delete']))
{
$sql = "SELECT * FROM images WHERE status = '1'";
$res = $connect->query($sql);
while($row = mysqli_fetch_array($res))
{
$id = $_POST['del'];
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'paspartu';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = 'DELETE FROM images
WHERE id='.$id;
mysql_select_db('login');
mysql_query($sql);
mysql_close($conn);
}
}
?>
</form>
If pressed the delete button <input class="btn btn-danger" name="delete" type="submit" value="истрии"> , this delete the last upload image???
And can you tell me how to delete the image from upload folder "uploads/"? Thank you verry much.
It's because you don't have an input in your form that's named "showFilter". You need to either rewrite or remove:
if (isset($_POST["showFilter"]))
Try modified query delete
$sql = "DELETE FROM `your_database`.`images` WHERE `your_database`.`id` = $del_id";
As I can see your submit button is in separate form tag. That is why the button is responsible only for the first parent form and if it is pressed the page is only reloaded. It should be placed in the general form you use, so that it will be related with the general form action.
You need to take your submit button inside the form. You have used two different forms. It is the problem.
Try to write your code as below:-
<?php
// Take div and form tag outside the loop
echo "<div class='col-md-3 picture'>
<form class='form' method='POST'>";
// Loop start
while($row = mysqli_fetch_array($resFilter))
{
echo "<img class='child-img' src='".$row["picture"]." '/></br>
<div class='number'>
<span class='id'>№ ".$row['id']."
<input class='check' name='checkbox[]' type='checkbox' value='". $row['id']."'></br>
име: ".$row['img_content']."</br> категория: ".$row['category']."</br>
цена: ".$row['price']."лв.</br>
дата: ".$row['time']."ч.
</br></span>
<br></div>";
}
// Loop End
?>
<!-- submit button -->
<input class="btn btn-danger" name="delete" type="submit" value="истрии маркираните">
<?php
// end div and form tag outside the loop
echo "</form>
</div>";
if (isset($_POST['delete']) && isset($_POST['checkbox'])) {
foreach($_POST['checkbox'] as $del_id){
$del_id = (int)$del_id;
$sql = "DELETE FROM images WHERE id = $del_id";
mysql_query($sql);
}
header('Location: admin.php');
}
Hope it will help you :)