Jump to content

checkbox form into db


Recommended Posts

Hi everyone, I currently have a form which allows users to select a value from a dropdown and insert it into the table, I need to modify this option now so the user can  select multiple uptions and isnert them into the table. Has anybody built something similiar to this before or know where I can find a solution? my current code is

<label for="workconsidered_1">Workconsidered:</label></td>
          <td><div>
            <input <?php if (!(strcmp(KT_escapeAttribute($row_rs_model_biographies_['workconsidered']),"1"))) {echo "@@checked@@";} ?> type="radio" name="workconsidered" id="workconsidered_1" value="1" />
            <label for="workconsidered_1">Portrait</label>
          </div>
            <div>
              <input <?php if (!(strcmp(KT_escapeAttribute($row_rs_model_biographies_['workconsidered']),"2"))) {echo "@@checked@@";} ?> type="radio" name="workconsidered" id="workconsidered_2" value="2" />
              <label for="workconsidered_2">Catwalk</label>
            </div>
            <div>
              <input <?php if (!(strcmp(KT_escapeAttribute($row_rs_model_biographies_['workconsidered']),"3"))) {echo "@@checked@@";} ?> type="radio" name="workconsidered" id="workconsidered_3" value="3" />
              <label for="workconsidered_3">Glamour</label>
            </div>
            <div>
              <input <?php if (!(strcmp(KT_escapeAttribute($row_rs_model_biographies_['workconsidered']),"4"))) {echo "@@checked@@";} ?> type="radio" name="workconsidered" id="workconsidered_4" value="4" />
              <label for="workconsidered_4">Implied Topless</label>
            </div>
            <div>
              <input <?php if (!(strcmp(KT_escapeAttribute($row_rs_model_biographies_['workconsidered']),"5"))) {echo "@@checked@@";} ?> type="radio" name="workconsidered" id="workconsidered_5" value="5" />
              <label for="workconsidered_5">Implied Nude</label>
            </div>
            <div>
              <input <?php if (!(strcmp(KT_escapeAttribute($row_rs_model_biographies_['workconsidered']),"6"))) {echo "@@checked@@";} ?> type="radio" name="workconsidered" id="workconsidered_6" value="6" />
              <label for="workconsidered_6">Glamour Topless</label>
            </div>
            <div>
              <input <?php if (!(strcmp(KT_escapeAttribute($row_rs_model_biographies_['workconsidered']),"7"))) {echo "@@checked@@";} ?> type="radio" name="workconsidered" id="workconsidered_7" value="7" />
              <label for="workconsidered_7">Glamour Nude</label>
            </div>
            <div>
              <input <?php if (!(strcmp(KT_escapeAttribute($row_rs_model_biographies_['workconsidered']),"8"))) {echo "@@checked@@";} ?> type="radio" name="workconsidered" id="workconsidered_8" value="8" />
              <label for="workconsidered_8">Promotions</label>
            </div>
            <div>
              <input <?php if (!(strcmp(KT_escapeAttribute($row_rs_model_biographies_['workconsidered']),"9"))) {echo "@@checked@@";} ?> type="radio" name="workconsidered" id="workconsidered_9" value="9" />
              <label for="workconsidered_9">Other</label>

Link to comment
https://forums.phpfreaks.com/topic/202201-checkbox-form-into-db/
Share on other sites

Is there any reason not to wrap the whole area in php?? This will clean up your code a bit. Also, if you are looking to use multiple values, each checkbox will need to have the same name like so:

 

// initialize the new array
$work = array();
// begin the related checkboxes
<input type="checkbox" name="$work[]" value="work_considered_xyz" />

 

the name attribute being set to the $work[] array

 

ALSO, i would do it this way:

<?php
echo '<td><div>
if(~conditiion exists~){
   echo '<label for="workconsidered_1">Workconsidered:</label></td>';
   echo '<input  type="radio" name="workconsidered" id="workconsidered_1" value="1" (~condition~ ? checked="checked" : NULL)  />
}
?>

 

so on and so forth. You don't need all those @ symbols... this will cleanup your code a bit. the stuff after the value in the input is called a ternary conditional. you can look that up but essentially it means

 

(check for this condition ? if the condition was true, do this : if not do this)

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.