Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHP: add a download as pdf file button in report page
- Formatting my post
- How to blend adsense inside your post?
- PHPWind-- A PHP forum script applcaition in China
- Google Adsense forum and pin number
- Promote your Forum/Blog/Website via major search Engines
- ActionScript 3.0 demo: create a falling snow in flash CS6
- Datatable export excel wraptext and newline
- Linux, automatically backup MySQL database daily
- Using Cron Job to process PHP scripts
Friday, March 8, 2013
PHP form submission with check box, radio button and dropdown menu
1. For PHP checkbox form submission, we still can only need one column in MySQL using PHP bitwise function &. (note we can have multi-choice in checkbox). Example code :
<input type="checkbox" name="competency[]" value="4" <?php if(($row['competency']&4) == 4){ echo('checked="checked"'); } ?> /> Hard skill
<input type="checkbox" name="competency[]" value="2" <?php if(($row['competency']&2) == 2){ echo('checked="checked"'); } ?> /> Soft skill
<input type="checkbox" name="competency[]" value="1" <?php if(($row['competency']&1) == 1){ echo('checked="checked"'); } ?> /> Others
In the action side:
$comp =0;
foreach($_POST['competency'] as $pc) {
$comp = $comp + intval($pc);
}
and insert $comp in database as column competency, which will be used in $row['competency']
2. For dropdown menu:
<select name="competency" id="competency">
<option value="">- select -</option>
<option value="3" <?php if($row['competency'] == 3){ echo('selected="selected"'); } ?> > Hard skill </option>
<option value="2" <?php if($row['competency'] == 2){ echo('selected="selected"'); } ?> > Soft skill </option>
<option value="1" <?php if($row['competency'] == 1){ echo('selected="selected"'); } ?> > Others </option>
</select>
In the action side:, we can insert $_POST['competency'] as it is a unique value.
3. For radio button:
<input type="radio" id="c1" class="input-radio" name="competency" value="3" <?php if($row['competency'] == 3){ echo('checked="checked"'); } ?> />
<label for="c1">Yes, with hard skill</label>
<input type="radio" id="c2" class="input-radio" name="competency" value="2" <?php if($row['competency'] == 2){ echo('checked="checked"'); } ?> />
<label for="c2">Yes, with soft skill</label>
<input type="radio" id="c3" class="input-radio" name="competency" value="1" <?php if($row['competency'] == 1){ echo('checked="checked"'); } ?> />
<label for="c3">No</label> <br />
In the action side:, we can insert $_POST['competency'] as it is a unique value.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment