Delete image(s) associated with record from folder - php

I have a page that allows for multiple record deletes using checkboxes and all works fine.
However, each record may have an image associated with it stored in a folder that would also need to be deleted but I have no idea how to achieve this even though I've searched Stackoverflow and Google.
How do I delete the record(s) from the MySQL database and the image(s) associated with it from the folder?
What I have so far is:
The code that deletes the records:
if ( isset( $_POST[ 'chk_id' ] ) ) {
$arr = $_POST[ 'chk_id' ];
foreach ( $arr as $id ) {
#mysqli_query( $KCC, "DELETE FROM pageContent WHERE contentID = " . $id );
}
$msg = "Page(s) Successfully Deleted!";
header( "Location: delete-familyservices.php?msg=$msg" );
}
The form that selects the records to delete:
<form name="deleteRecord" id="deleteRecord" method="post" action="delete-familyservices.php">
<?php if (isset($_GET['msg'])) { ?>
<p class="alert alert-success">
<?php echo $_GET['msg']; ?>
</p>
<?php } ?>
<table width="100%" class="table table-striped table-bordered table-responsive">
<tr>
<th>Page Title</th>
<th>Page Text</th>
<th>Page Image</th>
<th>Delete</th>
</tr>
<?php do { ?>
<tr>
<td width="30%" style="vertical-align: middle">
<h4 style="text-align: left">
<?php echo $row_rsContent['contentTitle']; ?>
</h4>
</td>
<td width="45%" style="vertical-align: middle">
<?php echo limit_words($row_rsContent['contentData'], 10); ?> ...</td>
<td align="center" style="vertical-align: middle">
<?php if (($row_rsContent['contentImage']) != null) { ?>
<img src="../images/<?php echo $row_rsContent['contentImage']; ?>" class="img-responsive">
<?php } else { ?> No Image
<?php } ?>
</td>
<td width="5%" align="center" style="vertical-align: middle"><input type="checkbox" name="chk_id" id="chk_id" class="checkbox" value="<?php echo $row_rsContent['contentID']; ?>">
</td>
</tr>
<?php } while ($row_rsContent = mysqli_fetch_assoc($rsContent)); ?>
</table>
<p> </p>
<div class="form-group" style="text-align: center">
<button type="submit" name="submit" id="submit" class="btn btn-success btn-lg butt">Delete Selected Page(s)</button>
<button class="btn btn-danger btn-lg butt" type="reset">Cancel Deletion(s)</button>
</div>
</form>
The final piece of code, which is a confirmation script:
<script type="text/javascript">
$( document ).ready( function () {
$( '#deleteRecord' ).submit( function ( e ) {
if ( !confirm( "Delete the Selected Page(s)?\nThis cannot be undone." ) ) {
e.preventDefault();
}
} );
} );
</script>
I've seen the unlink() function mentioned but I don't know if this is what to use or have any idea how to incorporate it into the existing code if it is.

you'll have to use the path of the image which is stored on you database like so :
unlink(' the link of the images which is fetched from db'); // correct
don't forget to check for image existence file_exists() //

Got this from another site and a bit of trial and error.
if($_POST) {
$arr = isset($_POST['chk_id']) ? $_POST['chk_id'] : false;
if (is_array($arr)) {
$filter = implode(',', $arr);
$query = "SELECT *filename* FROM *table* WHERE *uniqueField* IN ({$filter})";
$result = mysqli_query(*$con*, $query);
while ($row = mysqli_fetch_object($result)) {
$pathToImages = "*path/to/images*";
{
unlink("{$pathToImages}/{$row->contentImage}");
}
}
// DELETE CAN BE DONE IN ONE STATEMENT
$query = "DELETE FROM *table* WHERE *uniqueField* IN ({$filter})";
mysqli_query(*$con*, $query);
$msg = "Page(s) Successfully Deleted!";
header("Location: *your-page.php*?msg=$msg");
}
}
Thanks to everyone who contributed.
Hope this is of some help to others.

Related

Saving session data and post it to database

I have a site where you can order some tickets. If someone makes an order, I want the order to be send to the database. Also I want to put the specific cart items in to be send to the database. See the model I use:
ORDERS CART ITEMS
id* id
amount order_id*
product_id
quantity
This is the code I use with the form:
<form action="index.php?page=cart" method="post" class="">
<table class=" table__nav">
<thead>
<tr>
<th class="p p--bold p--th th--ticket">Ticket</th>
<th class="p p--bold p--th th--name">Name</th>
<th class="p p--bold p--th th--quantity">Quantity</th>
<th class="p p--bold p--th th--price">Price per ticket</th>
<th class="p p--bold p--th th--itemtotal">Item Total</th>
</tr>
</thead>
<tbody>
<?php
$total = 0;
foreach($_SESSION['cart'] as $ticket) {
$ticketTotal = $ticket['ticket']['price'] * $ticket['quantity'];
$total += $ticketTotal;
?>
<tr>
<td>
<?php echo $ticket['ticket']['eye_cart']; ?>
</td>
<td>
<p class = "p--bold"><?php echo $ticket['ticket']['name']; ?></p>
</td>
<td>
<input class = "p td--quantity" type="number" name="quantity[<?php echo $ticket['ticket']['id'];?>]" value="<?php echo $ticket['quantity'];?>" class="replace" required />
</td>
<td>
<p>€<?php echo $ticket['ticket']['price'];?>,-</p>
</td>
<td>
<p>€<?php echo $ticketTotal;?>,-</p>
</td>
<td>
<td class="remove-item"><button type="submit" class="btn remove-from-cart" name="remove" value="<?php echo $ticket['ticket']['id'];?>">×</button></td>
</td>
</tr>
</tbody>
<?php } ?>
</table>
<div class="table__wrap">
<button type="submit" id="update-cart" class="btn btn--cart" name="action" value="update">
<img width="14" height="14" src="./assets/img/refresh.png" alt="refresh">
</button>
</img>
<p class="table__order--total"><span class="span--bold span--bold-no">Total:</span></p>
<p class="table__order--number"><span class="span--bold span--bold-no">€ <?php echo $total ?>,-</span></p>
</div>
<div class="table__wrap table__wrap--end">
<a class="p p__li p__li--light" href="index.php?page=register">
<button type = "submit" name ="action" value = "details" class="btn btn--big btn--big-2 btn--dark">your details -> </button></a>
</div>
</form>
When the user presses the button to go to "your details" I want to save an order with the total amount + the cart items with the order_id and quantity.
I'm using the MVC model for this but I can't really figure it out.
This is how my controller looks:
if ($_POST['action'] == 'details') {
$data = array(
'amount' => $total,
);
$insertedOrder = $this->orderDAO->insertOrder($data);
$this->set('insertedOrder', $insertedOrder);
if (empty($insertedOrder)) {
$errors = $this->orderDAO->validate($data);
$this->set('errors', $errors);
}
}
if ($_POST['action'] == 'details') {
$dataB= array(
'order_id' => ?,
'product_id' => $_SESSION['cart']['id']['ticket']['id'],
'quantity' => $_SESSION['cart']['quantity'],
);
$insertedCartItem = $this->orderDAO->insertCartItem($data);
$this->set('insertedCartItem', $insertedCartItem);
if (empty($insertedCartItem)) {
$errors = $this->orderDAO->validateB($dataB);
$this->set('errors', $errors);
}
}
And the next code is my DAO:
public function insertOrder($data){
$errors = $this->validate( $data );
if (empty($errors)) {
$sql = "INSERT INTO `orders` (`amount`) VALUES (:amount)";
$stmt = $this->pdo->prepare($sql);
$stmt->bindValue(':amount', $data['amount']);
if ($stmt->execute()) {
return $this->selectOrderById($this->pdo->lastInsertId());
}
}
return false;
}
public function insertCartItem($dataB){
$errors = $this->validateB($dataB);
if (empty($errors)) {
$sql = "INSERT INTO `cart_items` (`order_id` `product_id`,`quantity`) VALUES (:order_id, :product_id, :quantity)";
$stmt = $this->pdo->prepare($sql);
$stmt->bindValue(':order_id', $dataB['order_id']);
$stmt->bindValue(':product_id', $dataB['product_id']);
$stmt->bindValue(':quantity', $dataB['quantity']);
if ($stmt->execute()) {
return $this->selectCartItemById($this->pdo->lastInsertId());
}
}
return false;
}
The main problem I have is that I don't know how I can send data from $_SESSION variables to the database. I run into problems in the controller. As you can see I'm sending data with the $data and $dataB, but I think I'm going wrong there.

Cannot Input image to database. Image File Upload Error: Undefined index: file_img

Hi everyone i need some help regarding this error. Im trying to create a module that will allow users to upload their image and display it to the other page. I am using 3 forms (index.php for displaying, create.php for sql query and addform.php for adding records). But everytime I run the program it always shows an error: Undefined index: file_img
index.php
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="assets/jquery-1.11.3-jquery.min.js"> </script>
</head>
<body>
<div class="container">
<h2 class="form-signin-heading">Employee Records.</h2><hr />
<button class="btn btn-info" type="button" id="btn-add"> <span class="glyphicon glyphicon-pencil"></span> Add Employee</button>
<button class="btn btn-info" type="button" id="btn-view"> <span class="glyphicon glyphicon-eye-open"></span> View Employee</button>
<hr />
<div class="content-loader">
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Photos</th>
</tr>
</thead>
<?php
require_once 'dbconfig.php';
$sql = $db_con->prepare("select id, name, content, imgname from tblkeanu");
$sql->execute();
while($result=$sql->fetch(PDO::FETCH_ASSOC))
{
echo '<tr>';
echo '<td>' . $result["name"] . '</td>';
echo '<td>' . $result["content"] . '</td>';
echo "<td><img src = 'images/" . $result['imgname'] . "' height='350px;' width='300px;' class='img'></td>";
echo "<td><a id = $result[id] class = 'edit_link' href='#' title = 'EDIT'> EDIT </a></td>";
echo "<td><a id = $result[id] class = 'delete_link' href='#' title = 'DELETE'> DELETE </a></td>";
echo ' </td>';
echo '</tr>';
}
?>
</table>
</div>
</div>
<br />
<div class="container">
<div class="alert alert-info">
Tutorial Link
</div>
</div>
</body>
</html>
create.php
<?php
require_once 'dbconfig.php';
if($_POST)
{
$name = $_POST['txtname'];
$content = $_POST['txtcontent'];
$filetmp = $_FILES['file_img']['tmp_name'];
$filename1 = $_FILES['file_img']['name'];
$filetype = $_FILES['file_img']['type'];
$filepath = 'images/'.$filename1;
try{
move_uploaded_file($filetmp,$filepath);
$sql = $db_con->prepare("INSERT INTO `tblkeanu`(`name`, `content`, `imgname`, `imgpath`, `imgtype`) Values (:name,:content,:filename1,:filepath,:filetype)");
$sql->bindParam(":name",$name);
$sql->bindParam(":content",$content);
$sql->bindParam(":filename1",$filename1);
$sql->bindParam(":filetype",$filetype);
$sql->bindParam(":filepath",$filepath);
if($sql->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
addform.php
<form method='post' id='emp-SaveForm' action="#" enctype="multipart/form-data">
<table class='table table-bordered'>
<tr>
<td>Title</td>
<td><input type='text' name='txtname' class='form-control' placeholder='EX : john doe' required /></td>
</tr>
<tr>
<td>Content</td>
<td><input type='text' name='txtcontent' class='form-control' placeholder='EX : Web Design, App Design' required></td>
</tr>
<tr>
<td>Photo</td>
<td><input type='file' name='file_img'/></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
<span class="glyphicon glyphicon-plus"></span> Save this Record
</button>
</td>
</tr>
</table>
The tricky part here is if i combined the addform.php to create.php and address bar is "..../..../create.php" the program runs smoothly and the input type was identified. but i need these 2 to be separated and not combined on one page so the webpage will not be refreshed everytime because im also using a javascript and jquery and the address should only be "..../..../index.php".
It will be much appreciated if you could help me out.
In your addform.php file the form dosen't have an action yet, The form action should be create.php.
In the create.php file the condition:
if($sql->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
Should be modified as :
if($sql->execute())
{
header("Location: index.php");
}
else{
echo "Query Problem";
}
This way after saving the records to the database you will be redirected to index.php .
**IN This Section **
<tr>
<td>Photo</td>
<td><input type='file' name='file_img'/></td>
</tr>
Please try this edit, It may help..
<tr>
<td>Photo</td>
<td><input type='file' name='file_img' accept='image/*'/></td>
</tr>

Data from controller not going to view (PHP Codeigniter)

I'm trying to get the $data from my controller to go into my view but it does not seem to be working. I keep getting a "variable does not exist" error. Here's the Controller code (view is loaded in a different part).
$affiliate_id = $this->input->get_post('affiliate_id');
$product_id = $this->input->get_post('product_id');
$data = array();
if (empty($affiliate_id)
&& empty($product_id))
{
$this->session->set_flashdata('error', 'Please enter an affiliate ID, a product ID, or both.');
redirect('admin/affiliate_relationship');
}
if (empty($affiliate_id))
{
$data['affiliate_relationship'] = $this->AffiliateRelationship->search_for_affiliate_by_product_id($product_id);
}
elseif (empty($product_id))
{
$data['affiliate_relationship'] = $this->AffiliateRelationship->search_for_affiliate_by_affiliate_id($affiliate_id);
$affiliate = $affiliate_id;
}
elseif (!empty($affiliate_id)
&& !empty($product_id))
{
$data['affiliate_relationship'] = $this->AffiliateRelationship->search_for_affiliate($affiliate_id, $product_id);
$affiliate = $affiliate_id . '/';
}
$data['affiliate_id'] = $affiliate_id;
$data['product_id'] = $product_id;
redirect_and_continue_processing('admin/affiliate_relationship/' . $affiliate . $product_id, $data);
When I pr($data) I get the array correctly, so I know the data is all there. It's just when it is used in the view it does not even exist.
Am I doing something wrong? I've done other controller and views more-or-less the same way and never got problem this before.
EDIT: View code.
<?php
$affiliateRelationshipRows = NULL;
if (!empty($affiliate_relationship))
{
$class = NULL;
$i = 0;
foreach ($affiliate_relationship->result_array() as $affiliate)
{
if (++$i%2 == 0)
{
$class= ' class="odd"';
}
else
{
$class = NULL;
}
$affiliateRelationshipRows .= <<<END
<tr $class>
<td class="text-left">{$affiliate['id']}</td>
<td class="text-left">{$affiliate['product_id']}</td>
<td class="text-left">{$affiliate['user_id']}</td>
<td class="text-left">{$affiliate['affiliate_status_id']}</td>
<td class="text-left">{$affiliate['created']}</tD>
<td class="text-left">{$affiliate['custom_payout']}</td>
<td class="text-left">{$affiliate['delayed']}</td>
<td class="text-left">{$affiliate['sales_page_url']}</td>
<td class="text-left">{$affiliate['comments']}</td>
</tr>
END;
}
}
?>
<?php echo form_open($this->uri->uri_string()); ?>
<div class="box-search">
<div class="grid-2" style="width:200px; margin-left:25px;">
<span class="label" style="float:none;">
Affiliate ID:
</span>
<span class="field" style="float:none;">
<input type="text" name="affiliate_id" value="<?php if (!empty($affiliate_id)) { echo $affiliate_id; } ?>" style="width: 75px;"/>
</span>
<?php echo form_error('affiliate_id'); ?>
</div>
<div class="grid-2" style="width:200px; margin-left:0px;">
<span class="label" style="float:none; ">
Product ID:
</span>
<span class="field" style="float:none;">
<input type="text" name="product_id" value="<?php if (!empty($product_id)) { echo $product_id; } ?>" style="width:75px;"/>
</span>
<?php echo form_error('product_id'); ?>
</div>
RESET
<input type="submit" name="search" class="btn btn-green btn-mini-submit btn-search" value="SEARCH"/>
<div class="clear"></div>
</div>
<?php echo form_close(); ?>
<div class="box">
<div class="top">
Affiliate Relationship
</div>
<div class="main-table">
<table class="style1" cellpadding="2" cellspacing="0" width="100%" border="0">
<thead>
<tr>
<th>ID</th>
<th>Product ID</th>
<th>User ID</th>
<th>Affiliate Status ID</th>
<th>Created</th>
<th>Custom Payout</th>
<th>Delayed</th>
<th>Sales Page URL</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<?php echo $affiliateRelationshipRows; ?>
</tbody>
</table>
</div>
The array:
Array
(
[affiliate_relationship] => Array
(
[0] => stdClass Object
(
[id] => 11615304
[created] => 2015-09-17 00:00:00
[product_id] => 175538
[user_id] => 393598
[comments] =>
[affiliate_status_id] => 2
[custom_payout] =>
[delayed] => 0
[sales_page_url] =>
)
)
[affiliate_id] => 11615304
[product_id] => 175538
)
I don't think you can send data like that in redirect_and_continue_processing() or redirect() in codeigniter. The only way to do that is by sending the data as an argument to the function that you are trying to redirect to. Then in that function, use the data to generate the view.
LIke :
redirect_and_continue_processing('admin/affiliate_relationship/' . $affiliate . $product_id/$data);
And in the method "affiliate_relationship" , accept the argument
Redirect method does not take an argument as the variable to send to view.
instead of using
redirect_and_continue_processing('admin/affiliate_relationship/' . $affiliate . $product_id, $data);
you can use simple way to do this
$this->load->view('your_view_name','your data in array');

Delete multiple image from database also database using codeigniter

I just created code that deletes an image from database and also from folder which is an image store, but only one image is successfully deleted from thedatabase and folder when I click "check all". What did I do wrong? Here is my view using check box javascript:
<form name="indonesia" action="<?php echo site_url('admin/wallpaper/delete'); ?>" method="post">
<button type="submit" class="btn btn-danger" name="hapus" value="hapus">Hapus</button>
<?php echo anchor('admin/wallpaper/tambah', 'Tambah Wallpaper');?>
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>
<button type="button" class="btn btn-info" onClick="check_all()" >Check</button>
<button type="button" class="btn btn-success" onClick="uncheck_all()" >Un-Check</button>
</th>
<th>id</th>
<th>Keterangan</th>
<th>Gambar</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
foreach ($ListWallpaper->result() as $row)
{
?>
<tr>
<td><input type="checkbox" name="item[]" id="item[]" value="<?=$row->id_wall ?>"></td>
<td><?=$row->id_wall ?></td>
<td><?=$row->ket ?></td>
<td><?=$row->wall ?></td>
<td>
Delete
Update
</td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
and here is my controller
public function delete()
{
$ownerNames = $this->input->post('item');
foreach ($ownerNames as $ownerName => $k) {
//echo "Array : " . $k . "<br/>";
$photo = $this->wallpaper_model->del_photo($k);
if ($photo->num_rows() > 0)
{
$row = $photo->row();
$file_photo = $row->wall;
echo "$file_name</br>";
$path_file = 'image/wallpaper/';
unlink($path_file.$file_photo);
}
$this->wallpaper_model->drop_photo($k);
redirect('admin/wallpaper','refresh');
}
}
and my model
function del_photo($k)
{
$this->db->where('id_wall',$k);
$query = $getData = $this->db->get('tabel_wall');
if($getData->num_rows() > 0)
return $query;
else
return null;
}
function drop_photo($k)
{
$this->db->where('id_wall',$k);
$this->db->delete('tabel_wall');
}
Only one image is successfully deleted from the folder and database too, but when I try to echo "$file_name</br>"; it show all images. What did I do wrong? if anyone can guide me, I will appreciate that.
First off I would set a array of images from controller to view, $data['wallpapers'] = array(); for some of the site_url you may need to include in your route.php $route['controller/update/(:any)'] = "controller/update/$1"
To Delete selected images, You could do a selected post in array() and then on the value check box name=""
Disclaimer: This is just for a example only.
public function index() {
$k = $this->uri->segment(what ever); // Use uri segment is id example.com/image/1 = $this->uri->segment(2);
$results = $this->model_name->del_photo($k);
$data['wallpapers'] = array();
foreach ($results as $result) {
$data['wallpapers'][] = array(
'id_wall' => $result['id_wall'],
'update' => site_url('controllername/update' .'/'. $result['wall_id']),
'ket' => $result['ket']
);
}
$data['delete'] = site_url('controller/function');
$selected = $this->input->post('selected');
if (isset($selected)) {
$data['selected'] = (array)$selected;
} else {
$data['selected'] = array();
}
$this->load->view('your list', $data);
}
public function update() {
//update info here
}
public function delete() {
$selected = $this->input->post('selected');
if (isset($selected)) {
foreach ($selected as $image_id) {
$wall_id = $image_id
$this->db->query("DELETE FROM " . $this->db->dbprfix . "TABLENAME WHERE wall_id = '" . (int)$wall_id . "'");
}
}
}
View
Added echo delete from controller as site url.
<form action="<?php echo $delete;?>" method="post">
<table>
<thead>
<tr>
<td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
<td>Update</td>
</tr>
</thead>
<tbody>
<?php if ($wallpapers) { ?>
<?php foreach ($wallpapers as $wallpaper) { ?>
<td class="text-center"><?php if (in_array($wallpaper['id_wall'], $selected)) { ?>
<input type="checkbox" name="selected[]" value="<?php echo $wallpaper['id_wall']; ?>" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="selected[]" value="<?php echo $wallpaper['id_wall']; ?>" />
<?php } ?>
</td>
<td>Update</td>
<?php } ?>
<?php } ?>
</tbody>
</table>
</form>
Model
function del_photo($k) {
$this->db->where('id_wall',$k);
$query = $this->db->get('table_name');
if($query->num_rows() > 0) {
$return = $query->result_array();
} else {
return false;
}
}
In controller, move redirect directive outside of foreach loop.

Multi checkbox post proplem

I wanna check same exist database, but doesn't work the $check. What's wrong ı cannot find.
ı taking this error when post;
error 1-Members not added :(
Mysql error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''459' at line 1
error 2- 459 memb_id already in databese, try again!
This is my code:
<?php
$row_data = array();
foreach($_POST['checkbox'] as $row=>$Name) {
$name=mysql_real_escape_string($Name);
$memb_id=mysql_real_escape_string($_POST['memb_id'][$row]);
$memb_srnm=mysql_real_escape_string($_POST['memb_srnm'][$row]);
$kur_id=mysql_real_escape_string($_POST['kur_id'][$row]);
$row_data = array("'$memb_id'", "'$memb_srnm'", "'$kur_id'");
}
if (!empty($row_data)) {
$check = mysql_query("SELECT * FROM basvurular WHERE memb_id='$memb_id");
if (mysql_affected_rows() ){
echo '<h4 class="alert_error"><strong>'.ss($memb_id).'</strong> already in databese, try again! </h4>';
header('Location: index.php');
} else {
$query = 'INSERT INTO basvurular (memb_id, memb_srnm, basvur_kurid) VALUES (' .implode(',', $row_data) . ')';
}
if (mysql_query($query)){
echo '<h4 class="alert_success"> <label style="color: blue; font-size: 26px; font-weight: bold;"><img style="width: 4%" src="images/pers2.png" alt=""/>-'.mysql_affected_rows().'- </label> Succesfull :) </h4>';
header('Location: index.php');
}else{
echo '<h4 class="alert_error">Members not added :( <br> Mysql Error:'.mysql_error().'</h4>';
return false;}
}
?>
<article class="module width_3_quarter" style="padding-bottom: 10px; width: 95%">
<header>
<div style="float:right;font-size:14px;font-weight: bold; padding:10px"></div>
<h3 class="tabs_involved">POST SELECTED</h3>
</header>
<div class="tab_container">
<?php
$query = query("SELECT * FROM members INNER JOIN kurumlar ON kurumlar.kur_id = members.kur_id WHERE kurumlar.kur_id=' ".$_SESSION["kur_id"]." ' && ceza=0 ORDER BY memb_id DESC");
if (mysql_affected_rows()){
?>
<div id="tab1" class="tab_content">
<?php echo '<form action="" method="post" name="frm" onsubmit="return check">
<table class="tablesorter" cellspacing="0"> '; ?>
<thead>
<tr>
<th><a style="text-decoration: none;font-size:14px;font-weight: bold; color: blue" href="javascript:void(0);" id="link" onclick="slct()">All Select</a></th>
<th align= "left" >ID Number</th> <th></th>
<th align= "left" >USER NAME</th><label style="padding-right: 10px;padding-bottom: 10px;float:right " ><input style="color: red" type="submit" name="post" value="Selected Post"></label>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
while ($row = row($query)){
?>
<tr>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]" ></td>
<td><?php echo ss($row["membName"]);?></td><td><input name="memb_id[]" type="hidden" value="<?php echo ss($row["memb_id"]);?>"></td>
<td><?php echo ss($row["memb_srnm"]);?></td><td><input name="memb_srnm[]" type="hidden" value="<?php echo ss($row["memb_srnm"]);?>"></td>
<td><input name="kur_id[]" type="hidden" value="<?php echo ss($_SESSION["kur_id"]);?>"></td>
</tr>
<?php }?>
</tbody>
<?php echo '</table></form>'; ?>
</div>
<?php }else{ ?>
<h4 class="alert_warning">Nobody Here :(( </h4>
<?php }?>
</div>
</article>
You're missing a quote on this line:
$check = mysql_query("SELECT * FROM basvurular WHERE memb_id='$memb_id'");
Also, to check whether a SELECT query returned any rows, you should use mysql_num_rows(), not mysql_affected_rows() -- the latter is only for queries that modify tables.
You should also check that the query is successful:
$check = mysql_query("SELECT * FROM basvurular WHERE memb_id='$memb_id")
or die(mysql_error());

Categories