Forum Moderators: coopster

Message Too Old, No Replies

checkbox values php/html

         

bilenkyj

10:17 am on Mar 27, 2008 (gmt 0)

10+ Year Member



i have a web form which is generated based on the number of rows in a db table. Each row has a check box with a name which is numeric - the form is within a loop giving each check box a unique number which is saved to an array.

When the form is submitted it passes the checkbox value onto a section of code which pupulates the database.

The issue is with the check box - if checked it will pass the word "Pending" and i assumed that if the check box isnt checked it passes "" or "NULL".

My query says update table column with Pending if value of checkbox is pending and update with word "Requested" is checkbox is empty/NULL

problem is that the check box to my script technically doesnt exisit as it is never checked - my array is then out of sync.

The question is can i have the checkbox set so that it sends a value regardless of if it is checked or not?
something like this -

<input type = "checkbox" name ="yespending[]" <?php if(CHECKED){echo "value=/"Pending/"";}else{echo "value=/"Requested/"";}>

what do you reckon?

Habtom

10:21 am on Mar 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If it is unchecked, it won't be set at all.

Try isset() [php.net].

bilenkyj

10:28 am on Mar 27, 2008 (gmt 0)

10+ Year Member



thats the issue though,
isset wont work either as the varible technically wont exisit if the check box isnt checked (i think)

im trying to make it virtually checked so to speak

its making me think i should just go with a drop down box

Habtom

10:36 am on Mar 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the varible technically wont exisit if the check box isnt checked

That is why the function exists.

Returns TRUE if var exists; FALSE otherwise.

Try something like the following:

<?php

$yespe = $_REQUEST['yespending']
if (isset($yespe)) {
echo "value=/"Requested/"";
} else {
echo "value=/"Pending/"";
}

?>

bilenkyj

10:54 am on Mar 27, 2008 (gmt 0)

10+ Year Member



ah i see, i havent used it before, didnt really know how it worked
but have put it in place and now seems really good, thanks for your help