View Full Version : "simple script" causing huge headache (literally)

06-06-2004, 09:03 AM
its 2:50 am, ive been at this "simple script" since I woke up. i cannot believe this script has caused me a huge headache.

as i'm about to go to bed, giving into my burnout, i decided to ask for help.

I have been googling arround and found that what i want is so basic, everyone and their neighboors have wanted to do this. I have found so many people explaining the same basic concept over ad over, yet i cant get this god forsaken script to work....

get ready for a cliche problem....

i have a form that repeats itself over and over with every entry done to my database, and i want to be able to delete them using checkboxes which last night i figured would require me to just tell it to have a value of "$id" and to pass it to an array....

this is exactly what everyone has told everyone else that couldnt get it to work, yet for some reason it dosn't seem that my script is passing the value "$id" at all...

this is my checkbox, forgive me if i am way off as i have tried many diffrent variations and i'm too out of it to put them back as i originally had them.

<input type="checkbox" name="checkbox[]" value="<?php $myrow["id"]; ?>">

this is my delete button

<form method="post" action="<?php $PHP_SELF ?>">
<input type="Submit" name="delete" value="Delete">

and this is my delete script

if ($delete) {
$sql = "DELETE FROM gb_guests WHERE id=$checkbox";

$result = mysql_query($sql);

echo "$sql Record deleted!<p>";

right now i dont have the mental capacity to figure out if they are still all corresponding, but i do however realize that that delete script would run into problems when i select more than one checkbox....

anyways, i hope someone can help me, i'm sorry if i didn't make much sense, i tried my hardest, but if i'm lucky, i'll have the answer when i wake up...

thanks for your help,

06-06-2004, 11:15 AM
your problem is that <?php $myrow["id"]; ?> prints nothing , you need to <?php echo $myrow["id"]; ?>

this would also work for multiple deletions ....

<input type="checkbox" name="checkbox[<?php echo $myrow["id"]; ?>]" value="1">

.. then (echo first to check its doing what you want it to do)

foreach($_POST['checkbox'] as $id=>$value ){
$sql="DELETE FROM $table WHERE id=$id";
echo $sql.'<br />'; //mysql_query($sql)or die(mysql_error());


06-06-2004, 05:13 PM
Yeah, i saw that checkbox wasn't getting the variable passed on, but everyone said thats how it was done, but now that i look at how you wrote that checkbox script, it makes a heck of a lot more sense, I'm going to go try it right now


06-06-2004, 05:26 PM
Nope, that didn't work, seems to me that for some odd reason, my array is getting

cleared when i press the "delete" button, any ideas? :confused: