deleting records with php and checkboxes

deleting records with php and checkboxes

am 29.11.2002 13:25:39 von angelo.rigo

Hi

I have the folowing two php?s to delete records from my database wich is
an event database,
it works typing the id field and clicking delete

I would like to put checkboxes in more than one record at time to delete
then. To make my script more advanced.

How can it be done?

i think i could put a checkbox with the default value "off (or 0)" and make
the delete.php delete the record with the checkbox with value "on (or 1)",
but the details to do this i need to discover
someone has passed by this situation, and could help me?

$db =3D pg_connect("dbname=3Dthedb user=3Dtheuser");
$query =3D "SELECT * FROM thetable";
$result =3D pg_exec($db, $query);
if (!$result) {printf ("ERROR"); exit;}
$numrows =3D pg_numrows($result);
$row=3D0;
printf ("


");
printf ("");
do
{
$myrow =3D pg_fetch_row ($result,$row);
printf ("
",$myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5], $myrow[=
6],$myrow[7]);
$row++;
}
while ($row < $numrows);
printf ("
IdCity=
state
LocationDayMonth >TimeEvent
%s%s%s%s td>%s%s%s%s


");
pg_close($db);
?>

Type the id to be deleted.


ID to Delete : ue=3D"">






Above is the delete.php


$db =3D pg_connect("dbname=3Dthedb user=3Dtheuser");
$query =3D "DELETE FROM thetable where id=3D'$id'";
$result =3D pg_exec($db, $query);
if (!$result) {printf ("ERROR"); exit;}
printf ("Deleted with sucess!");
pg_close($db);
?>

________________________________________
A busca mais veloz e precisa da internet. Acesse agora: http://www.zoom.com=
..br.



---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Re: deleting records with php and checkboxes

am 29.11.2002 18:22:14 von Frank Bax

At 07:25 AM 11/29/02, angelo.rigo@globo.com wrote:
>I have the folowing two php?s to delete records from my database wich is
>an event database,
>it works typing the id field and clicking delete
>
>I would like to put checkboxes in more than one record at time to delete
>then. To make my script more advanced.
>
>How can it be done?
>
>i think i could put a checkbox with the default value "off (or 0)" and make
>the delete.php delete the record with the checkbox with value "on (or 1)",
>but the details to do this i need to discover
>someone has passed by this situation, and could help me?
>
> >$db = pg_connect("dbname=thedb user=theuser");
>$query = "SELECT * FROM thetable";
>$result = pg_exec($db, $query);
>if (!$result) {printf ("ERROR"); exit;}
>$numrows = pg_numrows($result);
>$row=0;
>printf ("


>");
>printf (" >bgcolor='#66CCFF'>");
>do
>{
>$myrow = pg_fetch_row ($result,$row);
>printf (" >bgcolor='$bgcolor'>
>",$myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5],
>$myrow[6],$myrow[7]);
>$row++;
>}
>while ($row < $numrows);
>printf ("
IdCitystateLocationDayMonthTimeEvent
%s%s%s%s%s%s%s%s


>");
>pg_close($db);
>?>
>
>Type the id to be deleted.
>
>

>ID to Delete :

>
>
>

>
>
>Above is the delete.php
>
>
> >$db = pg_connect("dbname=thedb user=theuser");
>$query = "DELETE FROM thetable where id='$id'";
>$result = pg_exec($db, $query);
>if (!$result) {printf ("ERROR"); exit;}
>printf ("Deleted with sucess!");
>pg_close($db);
>?>

Checkbox doesn't work like other form elements. Other form elements always
get returned. Checkbox ony gets sent back when it is checked. Therefore,
make the value of the checkbox the value of id you want deleted, make it's
name an array like id[] instead of simply id.

Then your delete code will look something like:
$id = $HTTP_POST_VARS[id];
for( $n=0; $n < count($id); $n++ ) {
if( strlen($id[$n])>0 ) {
$sql="DELETE from thetable WHERE id='" . $id[$n] ."'";
pg_exec( $sql );
}
}

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)