473,326 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

delete multiple record via echoing checkbox

Hi!

I want to delete multiple record via checkboxes. However, with no success.
Is there sthg wrong with the value of my checkbox?

Your help will be greatly appreciated. Thanks!

<form name="form1" method="post" action="">
<p>
<?php

$cName = trim($_POST['cname']);

//echo "Cname is ".$cName;

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Error in connecting ");

mysql_select_db($dbname) or die ("Error in using database");

$qur = "SELECT * FROM contacts";

if($cName != ""){ //user does not want to search for all contact. some thing was entered in txt box
//$qur .= " WHERE contactname ='".$cName."'";
$qur .= " WHERE contactname LIKE '%".$cName."%'";
}

$qur .= " ORDER BY userid"; //sort

//echo "qur is".$qur;
//Execute query and store records returned by SELECT
$res = mysql_query($qur);

//Check if any results are returned
if(mysql_num_rows($res) == 0){
echo "<i>No Staff contacts found.</i><br>";
} //if
elseif (mysql_num_rows($res) > 0) { //cannot be -1!!!
//fetch the rows as assoc array

echo "<table border = 1 width=70% align='center' >";
echo "<th><input type='checkbox' name='sAll' onClick='checkUncheckAll(this);'/>".$row['']."</th><th>ID</th><th>Name</th><th>E-mail Address</th><th>Contact Number</th><th>Edit</th>";
while($row = mysql_fetch_array($res)){
//one table row (tr) for each record in record set res
$ii = $row['userid'];
echo "<tr><td align='center'><input type='checkbox' id='checkbox[]' name= 'checkbox[]' value= '".$row['userid']."'/>".$row['']."</td><td align='center'>".$row['userid']."</td><td align='center'>".$row['contactname']."</td><td align='center'>".$row['email']."</td><td align='center'>".$row['phone']."</td><td align='center'>
<a href='edit-contact.php?userid=".$ii."'>Edit</a></td></tr>";


// Check if delete button active, start this
if($delete){
for($i=0;$i<$count;$i++){
$del_userid = $checkbox[$i];
$sql = "DELETE FROM contacts WHERE userid='$del_userid'";
$res = mysql_query($sql);
}

// if successful redirect to delete_multiple.php
if($res){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=list_contact.php\">";
}
}


}//end while
echo "</table>";

} //else

} //if isset()

else { //trying to access this page without logging-in
echo "<center>";
echo "<br>";
echo "You are not authorized to view this page!";
echo "</br>";
echo "<br>";
echo "<br>";
echo "<a href='index.html'>Log in</a>";
echo "</br>";
echo "</br>";
echo "</center>";
die ("");
} //else
//close database connection
include 'closedb.php';
?>
</p>
<pre> <input type="submit" name="delete" id = "delete" value="Delete">
</pre>
<p>

</p>
</form>
Jun 29 '08 #1
1 2784
Markus
6,050 Expert 4TB
I cant make sense of your code.

Use [code] tags.
Jun 29 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
1
by: Ken | last post by:
Is this a correct statement to delete a row in a table named "ad_data"? mysql_query("DELETE FROM ad_data WHERE id = $_SESSION"); The connection is open. $_SESSION echo's as 220 which is...
1
by: Wolffang | last post by:
From: "Wolffang" <javid@techlite.co.uk> Subject: How to do a multiple select and update in a datagrid Date: 23 October 2004 21:28 Using Visual studio.net VB I have a datagrid that brings...
9
by: Dejan | last post by:
Hy, Sorry for my terreble english I have this simple code for deleting rows in mysql table... Everything works fine with it. So, what do i wanna do...: my sql table looks something like...
1
by: saurabhbpl | last post by:
hi, i want to delete record that check by checkbox and also if i select all option than all record select delete after press the delete button like a yahoo email and hotmail.plz. give me suggestion,...
4
by: it2051229 | last post by:
Well i'm having a problem with the compatibility of javascript and PHP multiple delete check box.. i used a javascript for the "CHECK ALL BOXES" just like yahoo mail.. so my input is something like...
8
by: jmarcrum | last post by:
Hello all, i have a continuous form that displays about 1000 records and opens when I click a button. When the form opens, the user has the option of checking a checkbox that is located beside...
11
by: TechnoAtif | last post by:
INSERT AND UPDATE MULTIPLE CHECKBOX DATA USING PHPMYSQL OR JAVASCRIPT Hi All I want to check the multiple checkboxes update them after revisiting that page. I am taking the name as...
2
by: Michael | last post by:
It seems that a gridview allows us to delete only a single row at a time. How to extend this functionality to select multiple rows and delete all of the selected rows in a single stroke? just like...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.