Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Location
    Florida, USA
    Posts
    275
    Thanks
    0
    Thanked 0 Times in 0 Posts

    "simple script" causing huge headache (literally)

    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">
    </form>


    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,
    Ray

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,106
    Thanks
    11
    Thanked 101 Times in 99 Posts
    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());

    }
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Feb 2004
    Location
    Florida, USA
    Posts
    275
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    Thanks!

  • #4
    Regular Coder
    Join Date
    Feb 2004
    Location
    Florida, USA
    Posts
    275
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •