TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-15-2008, 02:27 AM   #1 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 10
Thanks: 0
riscphree is on a distinguished road
Default Multiple Checkbox problems

What I'm trying to do is delete items in a mysql database that are displayed with a simple checkbox. Here is the form that is generated.

Code:
<form action="" method="post">

sql query here

print"<input type="checkbox" class="delete-checkbox" value="{$row['id']}" name="deletebox[]" />";

<input type="submit" name="submit" value="delete messages" />
</form>
Here is the php that I'm using when its POSTED

Code:
if(isset($_POST['submit'])) {
foreach($_POST['deletebox'] as $deletebox1){
mysql_query("DELETE FROM private_messages WHERE id='$deletebox1'") or die(mysql_error());
}
}
However, nothing happens, which seems to be something with the array, but I can't figure it out. I've tried putting something to print out what is in the array that is passed, but it never prints anything out, like its blank. And I'm positive there are values in the deletebox[] value when you check it.
riscphree is offline  
Reply With Quote
Old 01-15-2008, 02:36 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Default

That code actually works perfectly for me. This is what I have:

php Code:
<?php

if(isset($_POST['submit']))
{
    foreach($_POST['deletebox'] as $deletebox1)
    {
        $deletebox1 = (int) $deletebox1;
        echo "DELETE FROM private_messages WHERE id=$deletebox1" . '<br />';
    }
}

?>

And the HTML...

html4strict Code:
<form action="" method="post">

    <input type="checkbox" class="delete-checkbox" value="1" name="deletebox[]" />
    <input type="submit" name="submit" value="delete messages" />

</form>

I can really only surmise that either the $_POST array is being overwritten, or that for whatever reason there are no items being posted, but I'm not sure why that would be. Is your code getting to that segment where you execute the SQL statements?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 01-15-2008, 02:56 AM   #3 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 10
Thanks: 0
riscphree is on a distinguished road
Default

Man, I've been going over this for hours .. still not working and I see absolutely nothing wrong. I'm pretty much to the point where I'll pay someone to fix this, it's getting out of hand.
riscphree is offline  
Reply With Quote
Old 01-15-2008, 03:01 AM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Default

I feel for you! I've been in similar situations where things defy all reason. Sadly though I'm off to bed any time soon Maybe you can post us a bit more of the code - considering it isn't too long. Or maybe a pastebin otherwise.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 01-15-2008, 07:36 AM   #5 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

When the html is loaded, can you view source and see if $row['id'] is filling in the blank correctly in your checkbox form field?

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-15-2008, 01:16 PM   #6 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 10
Thanks: 0
riscphree is on a distinguished road
Default

Quote:
When the html is loaded, can you view source and see if $row['id'] is filling in the blank correctly in your checkbox form field?
Yeah, it is being loaded.
riscphree is offline  
Reply With Quote
Old 01-15-2008, 05:11 PM   #7 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Please, oh please, turn error reporting on (error_reporting(E_ALL)) when in debug mode. The problem is in the printing business:

PHP Code:
print"<input type="checkbox" class="delete-checkbox" value="{$row['id']}" name="deletebox[]" />"
Why aren't the double quotes inside the print statement escaped or smth? Like so...

PHP Code:
print '<input type="checkbox" class="delete-checkbox" value="' $row['id'] . '" name="deletebox[]" />'
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-15-2008, 05:30 PM   #8 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 10
Thanks: 0
riscphree is on a distinguished road
Default

Quote:
The problem is in the printing business:
Because my real code is:

Code:
print "<div class=\"delete\"><input type=\"checkbox\" class=\"delete-checkbox\" value=\"{$row['id']}\" name=\"deletebox\" /></div>";
I just took out the escapes so it was easier to read.
riscphree is offline  
Reply With Quote
Old 01-15-2008, 06:54 PM   #9 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

They keep telling you:

Code:
print "<div class=\"delete\"><input type=\"checkbox\" class=\"delete-checkbox\" value=\"{$row['id']}\" name=\"deletebox\" /></div>";
should be:
Code:
print "<div class=\"delete\"><input type=\"checkbox\" class=\"delete-checkbox\" value=\"{$row['id']}\" name=\"deletebox[]\" /></div>";
You might not notice but the name of the delete box has the [] after the work deletebox now ;)...
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
Old 01-16-2008, 06:40 PM   #10 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 10
Thanks: 0
riscphree is on a distinguished road
Default

I've got it at least to recognize the number of items being submitted, but it doesn't pass the values still. when I checked three boxes it ouput:

Code:
Array
(
    [deletebox] => Array
        (
            [0] => 
            [1] => 
            [2] => 
        )

    [submit] => delete messages
)
riscphree is offline  
Reply With Quote
Old 01-17-2008, 07:33 AM   #11 (permalink)
The Acquainted
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 106
Thanks: 13
EyeDentify is on a distinguished road
Default

Are you submiting via a Ajax JavaScript POST call or GET .

Cause i have had trouble with values don´t being transfered in some cases because of the form element being laid out with the help of Table elements.

Can´t remebmer right now wich Framework i used but it was:
jQuery, Prototype, MooTools, or someone like that.

Just a thought.

/EyeDentify
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.
EyeDentify is offline  
Reply With Quote
Old 01-17-2008, 12:42 PM   #12 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 10
Thanks: 0
riscphree is on a distinguished road
Default

Nope, just doing a regular form submission.
riscphree is offline  
Reply With Quote
Old 01-17-2008, 01:27 PM   #13 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,381
Thanks: 5
Salathe is on a distinguished road
Default

Try using var_dump rather than print_r because the former will be able to show us the types of the values (integer, string, etc) as well as their actual value (e.g, FALSE does not display anything with print_r).
Salathe is offline  
Reply With Quote
Old 01-17-2008, 01:54 PM   #14 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

Try echoing the value out to the page and see if there is an id being shown to the browser.
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
Old 01-17-2008, 05:17 PM   #15 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 10
Thanks: 0
riscphree is on a distinguished road
Default

using var_dump
Code:
var_dump($_POST)
and checked three boxes (IDs of 37, 27, and 21)

Gives me:

Code:
array(2) { ["deletebox"]=>  string(0) "" ["submit"]=>  string(15) "delete messages" }
riscphree is offline  
Reply With Quote
Old 01-17-2008, 05:18 PM   #16 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 10
Thanks: 0
riscphree is on a distinguished road
Default

Quote:
Try echoing the value out to the page and see if there is an id being shown to the browser.
In the links, the IDs are properly shown.
riscphree is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:38 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design