You sound a little confused as to how php works...  Specifically the line
onclick="<?$_SESSION["delete"]="true";?>"

This is ALWAYS going to be executed, and before the user even clicks this
button.  When the user visits the page, php will set this session variable
to "true" (incidently as a rule of thumb, use =1 instead of ="true", it's
quicker to evaluate later) and THEN generate the html page, which will only
show:
onclick=""
since the php code gets evaluated but no output is given.  Since this
variable is now set, it makes no difference which button is pressed.

Fault picking over! :)  The solution:

You can give each submit button a different name, uniquely identifying which
button is pressed, like so:

<FORM METHOD=POST ACTION="handle_input.php">

<INPUT of various types>....
....
...

<!-- Here's the important bit -->
<INPUT TYPE=SUBMIT NAME=delete value="Delete Selected">
<INPUT TYPE=SUBMIT NAME=add value="Add items">
<INPUT TYPE=SUBMIT NAME=submit value="Submit Form">
</FORM>


As you can see, each will produce a unique value in the $_POST array.  If
they click the "Delete Selected" button, then the variable $_POST['delete']
will now contain "Delete Selected", but it is only necessary to test that
this variable is set and not empty. ie

<?
if (!empty($_POST['delete']) {

// the code that deletes stuff
exit();

}
if (!empty($_POST['add']) {

// I think you get it now ;)

}
?>

Ross


> -----Original Message-----
> From: Kit Kerbel [mailto:[EMAIL PROTECTED]]
> Sent: 21 August 2002 15:41
> To: [EMAIL PROTECTED]
> Subject: [PHP-WIN] Checkbox problem
>
>
> I have a page that lists entries made by users in the database.
> There are
> three types of entries.  Each type of entry is stored in their
> own table.
> My problem is this:  I want people to be able to click a checkbox next to
> any of the entries and press a delete button and delete those
> entries.  The
> only hang up is that the delete button works as a submit button and sends
> the checkbox arrays as post variables to the next page and I'm trying to
> figure out a way to send another post variable when you click delete.
> something like my_listings?delete=true.
> not sure how, or if you can even do this with a submit button.  I
> also have
> three other buttons on this page that do different things when pressed to
> the boxes checked.  I tried using
> onclick="<?$_SESSION["delete"]="true";?>" in the delete(submit)
> button but
> for some reason, this session variable is also set when I click the other
> buttons as well, I guess because they are submit buttons too?
> If you can
> make sense of any of this, maybe you can help.
>
> Thanx in advance,
> Kit
>
>
> //this is what I do if the variable is set
> // **Marking Listings as Deleted
> if($_SESSION["delete"]=="true")
> {
>       if(isset($_REQUEST["horse"]))
>       {
>               foreach($_REQUEST["horse"] as $value)
>               {
>                       odbc_exec($connection, "UPDATE tblHorse SET
> dDeleted = 1 where dHorseID =
> '".$value."'");
>               }
>       }
>               if(isset($_REQUEST["trailer"]))
>       {
>               foreach($_REQUEST["trailer"] as $value)
>               {
>                       odbc_exec($connection, "UPDATE tblTrailer
> SET dDeleted = 1 where
> dTrailerID = '".$value."'");
>               }
>       }
>               if(isset($_REQUEST["tack"]))
>       {
>               foreach($_REQUEST["tack"] as $value)
>               {
>                       odbc_exec($connection, "UPDATE tblTack SET
> dDeleted = 1 where dTackID =
> '".$value."'");
>               }
>       }
>
> }
> unset($_SESSION["method"]);
>
>
> //This is how i'm trying to set the variable
> <input type="image" src="images/button_activate.gif" width="114"
> height="19"
> border="0" >
> <input type="image" src="images/button_sold.gif" width="114" height="19"
> border="0" >
> <input type="image" src="images/button_renew.gif" width="114" height="19"
> border="0" >
> <input type="image" src="images/button_delete.gif" width="114"
> height="19"
> border="0" onclick="<?$_SESSION["delete"]="true";?>"></td>
>
>
> _________________________________________________________________
> Chat with friends online, try MSN Messenger: http://messenger.msn.com
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>


-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to