Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

delete multiple records

Explorer ,
Jan 11, 2007 Jan 11, 2007
I need to delete muliple records from a table called leag_leagues. I made a form on the first page and set the value of the checkboc to the value of my id for my table. I then want to pass it to the delete page where it deletes the record and redirects to the delete record complete page. I am using PHP and mySQL.
Any help would be appriciated.
TOPICS
Server side applications
819
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 11, 2007 Jan 11, 2007

"justin wendorf" <webforumsuser@macromedia.com> wrote in message
news:eo63mh$o11$1@forums.macromedia.com...
>I need to delete muliple records from a table called leag_leagues. I made a
> form on the first page and set the value of the checkboc to the value of
> my id
> for my table. I then want to pass it to the delete page where it deletes
> the
> record and redirects to the delete record complete page. I am using PHP
> and
> mySQL.
> Any help would be appriciated.
>

Name your checkboxes the same, using array notation, and put the record id
in the checkbox:

<input type="checkbox" name="blah[]" value="<?php echo
$row_recordset1['recordid'];?>">

Then, delete them using an if statement to check for hte form field:

if(isset($_POST["blah"])) {
$delete = implode(",",$_POST["blah"]);
$query = sprintf("DELETE FROM mytable WHERE recordid IN (%s)",$delete);

execute your query and redirect
}

Tom Muck
http://www.tom-muck.com


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 12, 2007 Jan 12, 2007
I get this error on the delete page
Warning: implode() [function.implode]: Bad arguments. in /home/jewuypq/public_html/srlanes/admin/deleteleagueconfirm.php on line 10
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 12, 2007 Jan 12, 2007
Without seeing your code it is hard to comment. Make sure you named your
fields using array notation.

Tom


"justin wendorf" <webforumsuser@macromedia.com> wrote in message
news:eo85fq$9cj$1@forums.macromedia.com...
>I get this error on the delete page
> Warning: implode() [function.implode]: Bad arguments. in
> /home/jewuypq/public_html/srlanes/admin/deleteleagueconfirm.php on line 10


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 12, 2007 Jan 12, 2007
here is my code on the start page:
<?php require_once('../Connections/test.php'); ?>
<?php
mysql_select_db($database_test, $test);
$query_leag_leagues = "SELECT * FROM leag_leagues ORDER BY leag_name ASC";
$leag_leagues = mysql_query($query_leag_leagues, $test) or die(mysql_error());
$row_leag_leagues = mysql_fetch_assoc($leag_leagues);
$totalRows_leag_leagues = mysql_num_rows($leag_leagues);

//prevents caching
header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: post-check=0, pre-check=0",false);
session_cache_limiter();
session_start();

//this should the the absolute path to the config.php file
//(ie /home/website/yourdomain/login/config.php or
//the location in relationship to the page being protected - ie ../login/config.php )
require('../config.php');

//this should the the absolute path to the functions.php file - see the instrcutions for config.php above
require('../functions.php');

//this is group name or username of the group or person that you wish to allow access to
// - please be advise that the Administrators Groups has access to all pages.
if (allow_access(admin) != "yes")
{
include ('../no_access.html');
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Slippery Rock Lanes Admin</title>
<style type="text/css">
<!--
body,td,th {
color: #000000;
}
body {
background-color: #CCCCCC;
}
a:link {
color: #999999;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #999999;
}
a:hover {
text-decoration: underline;
color: #666666;
}
a:active {
text-decoration: none;
color: #CCCCCC;
}
.style1 {color: #CCCCCC}
-->
</style></head>

<body>
<table width="100%" border="0" bgcolor="#FFFFFF">
<tr>
<td width="16%" rowspan="4" valign="top"><img src="../assets/admin_pin.png" width="125" height="570" /></td>
<td width="84%" bgcolor="#FFFFFF"><img src="../assets/admin_logo.png" width="541" height="56" /></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> <a href="adminhome.php">Home</a> - <a href="adminuser.php">Users</a> - <a href="adminleague.php">Leagues</a> - <a href="calendarevents.php">Calendar</a> - <a href="allys.php">Allys</a> - <a href="coupons.php">Coupons</a> - <a href="hours.php">Hours</a> - <a href="honorroll.php">Honor Roll</a> - <a href="email.php">Email</a> - <a href="stats.php">Stats</a> - <a href="../home.php">View Site </a></td>
</tr>
<tr>
<td height="470" valign="top" bgcolor="#FFFFFF"><form id="deleterecords" name="deleterecords" method="post" action="deleteleagueconfirm.php">
<table width="700" border="1">
<tr>
<td width="24"><div align="center"></div></td>
<td width="49"><div align="center">ID</div></td>
<td width="300"><div align="center">Name</div></td>
<td width="153"><div align="center">Start Date </div></td>
<td width="152"><div align="center">End Date </div></td>
</tr>
<?php do { ?>
<tr>
<td><div align="center">
<input name="id" type="checkbox" id="id[]" value="<?php echo $row_leag_leagues['leag_id']; ?>" />
</div></td>
<td><?php echo $row_leag_leagues['leag_id']; ?></td>
<td><?php echo $row_leag_leagues['leag_name']; ?></td>
<td><?php echo $row_leag_leagues['leag_startdate']; ?></td>
<td><?php echo $row_leag_leagues['leag_enddate']; ?></td>
</tr>
<?php } while ($row_leag_leagues = mysql_fetch_assoc($leag_leagues)); ?>
<tr>
<td colspan="5"><div align="right">
<input type="submit" name="Submit" value="Delete Records" />
</div></td>
</tr>
</table>
</form> <p></p></td>
</tr>
<tr>
<td valign="top" bgcolor="#FFFFFF"><div align="right" class="style1">This Web Site Is Powered By Myth Tech Administration Technologies </div></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($leag_leagues);
?>

And here is my code for the delete page:
<?php require("../config.php") ?>
<?php
$con = mysql_connect("localhost",$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name, $con);

if(isset($_POST["id"])) {
$delete = implode(",",$_POST["id"]);
$query = sprintf("DELETE FROM leag_leagues WHERE leag_id IN (%s)",$delete);

mysql_query($query);
?>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 12, 2007 Jan 12, 2007
The delete code is missing a closing bracket, but it should work, assuming
you have used your correct table name and field name in the sql.

Tom


"justin wendorf" <webforumsuser@macromedia.com> wrote in message
news:eo8ii6$p9i$1@forums.macromedia.com...
> here is my code on the start page:


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 12, 2007 Jan 12, 2007
I am still getting the following error:
Warning: implode() [function.implode]: Bad arguments. in /home/jewuypq/public_html/srlanes/admin/deleteleagueconfirm.php on line 11

This is odd because it should work.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 12, 2007 Jan 12, 2007
I found my problem... Thanks for your help.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 14, 2007 Mar 14, 2007
could you post the problem you had and solved?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 14, 2007 Mar 14, 2007
also how would you delete all the images deleted with a multiple delete?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2007 Mar 14, 2007
On Wed, 14 Mar 2007 11:14:08 +0000 (UTC), "Jansolo"
<webforumsuser@macromedia.com> wrote:

>also how would you delete all the images deleted with a multiple delete?

Get all the images associated with the record you want to delete and
use unlink.

http://hk.php.net/unlink
--
Steve Fleischer
steve at flyingtigerwebdesign dot com
Hong Kong
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 14, 2007 Mar 14, 2007
hi there,

what if there are multiple records to delete? I have used the above example, how would i get each image and then delete each in turn?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2007 Mar 14, 2007
Jansolo wrote:
> what if there are multiple records to delete? I have used the above example, how would i get each image and then delete each in turn?

Use a loop.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 14, 2007 Mar 14, 2007
any chance you could elaborate - sorry I am new to PHP (use to use cfmx - trying to save on hosting costs). I have looked up loads on loops but seem to be missing the key to it all.

I really appreciate the help.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2007 Mar 14, 2007
LATEST
Jansolo wrote:
> any chance you could elaborate - sorry I am new to PHP (use to use cfmx -
> trying to save on hosting costs). I have looked up loads on loops but seem to
> be missing the key to it all.

Without knowing what it is that you're trying to do, it's rather
difficult. All I know is that you want to delete some images. Where are
they? What sort of scenario are you talking about?

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines