Results 1 to 10 of 10

Thread: Need Some Help

  1. #1
    Join Date
    Aug 2012

    Lightbulb Need Some Help

    Helo there.
    I just started with building a program using PHP language.
    I created the database & also a form.

    But my problem is, I have checkboxes & radio buttons.
    How do i store their input?
    Do i have to create


    Thank you for reading.

  2. #2
    Join Date
    Jul 2010
    You would want to make a table of possible things that can be checked off.

    This is very basic sql, you need to read more about sql and relational databases. It is very important. Hint: primary/foreign keys
    I use (, ; : -) as I please- instead of learning the English language specification: I decided to learn Scheme and Java;

  3. #3
    Join Date
    Jun 2006
    Under your bed
    Oooh I know how to do this! I try to help people on this forum but most questions are too complicated for me. I'm only intermediate at PHP.

    Anyhooooooooo. Here goes. Okay, say you have a checkbox question that asks "What colors do you like?" And then you have a checkbox for blue, one for red, one for yellow, and one for green, right? Well, you're going to give all those checkboxes the same name and put a [] after it. Watch:

    PHP Code:
    <strong>What colors do you like?</strong>
    br /><br />
    input type='checkbox' name='color[]' value='red' /> Red
    <br /><input type='checkbox' name='color[]' value='blue' /> Blue
    <br /><input type='checkbox' name='color[]' value='yellow' /> Yellow
    <br /><input type='checkbox' name='color[]' value='green' /> Green 
    Now, lets turn our attention to how the form will be submitted. Do you recognize the following tag?

    PHP Code:
    <form action='somepage.php' method='get'
    That goes at the beginning of a form. See method='get'? That means the information entered in the form will be submitted through the URL. If you don't want to do this, use "post" in place of get, like this: method='post'

    Now turn your eyes to action='somepage.php'. Replace somepage.php with the page you want to process the form. Let's just call it formprocessor.php for now.

    Okay, when you submit the form, the information will go to formprocessor.php If you used "get" as your method the information will be put inside a variable called "$_GET", if you used "post", the info will be in "$_POST".

    To access something in $_GET or $_POST you use what you named the field. So, like, for our "color" field, if we submitted it for $_GET it's in $_GET['color'] and likewise if it was with post then $_POST['color'].

    Because we used the [] things, if somebody checks multiple boxes and submits the form, PHP is going to put those multiple answers into an array. Like if they picked blue, green, and red, $_GET['color'] is going to have an array like this in it:

    [0] => red
    [1] => blue
    [2] => green
    If you want to see this for yourself, go to formprocessor.php and do this:

    PHP Code:
    print '<pre>';
    (If you used post then replace GET with POST.) Go to your page with the form, check multiple answers, and submit it.

    Erase the code I just showed you because you're not going to actually use that code to process your script. This is just a nice way of looking at what is in that array.

    Anyhoo, now, having multiple answers combined into an array is well and good, but how do we store it in the database? Well, it kind of depends on what you want. Do you want to store them in one field or multiple fields? Storing them in one field is easiest for me to explain so I'll show you that.

    You can use the function implode() to compress an array into a string. I don't know how to explain what a string is except you are going to hear that word a lot and it, is like, just a collection of characters like letters, number, spaces, etc. It's nothing fancy like an array. Anyway, do this with $_GET['color']:

    PHP Code:
    $colorCompressed implode(','$_GET['color']); 
    $colorCompressed was an arbitrary name I chose. $_GET['color'] contains the original array and I wanted somewhere convenient to stick the imploded one. The process is the same with $_POST.

    So the array, now turned into a string, looks like this:

    It's ready to stick in the database.

    Later on, if you get it back out of the database, and want to turn it back into an array, you can use explode() So, okay, let's say you got it out of the database and ended up sticking it in the varible $color; Well here is what you would do:

    $color = explode($color);

    This would take "red,blue,green" in color, turn it into an array just like it was before, and stick it back in $color.

    Now, radio buttons are different from checkboxes. You can't select multiple answers. At least, you shouldn't be able to. The only way HTML can tell that a set of radio buttons go together is if they all have the same name. So like if you ask the question "Which color is your favorite?" you name each radio button the same thing, "color" for instance.

    Since only one answer is selected, you don't have to worry about messing with arrays or anything. The answer is going to be submitted just anything else in the form, e.g. If you had <input type='text' name='firstName'> and somebody entered "Larry", that would create $_GET['firstName'] or $_POST['firstName'] with the value "Larry"

    So, you could just use $_GET['color'] or $_POST['color'] to access the value.

    Hope this helps. Let us know if there are any more problems.
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  4. #4
    Join Date
    Mar 2008
    Nice reply evenstar7139 I like the detail.

  5. #5
    Join Date
    Jun 2006
    Under your bed

    I enjoy explaining things, if you haven't already figured that out ^_^
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  6. #6
    Join Date
    Aug 2012
    Thank you for all the reply.
    I will give it a shot.

  7. #7
    Join Date
    Aug 2012
    I get the idea but I still dont understand how to stor the date into the database.

  8. #8
    Join Date
    Mar 2009
    hmm... how actually you want to store your data. you may store those checkbox values as a,b,c using implode or in a json array or a simply serialize and store

    would love to see your latest code to understand and reply better.

  9. #9
    Join Date
    Aug 2012
    I'll try to post the latest coding by the end of this week.

  10. #10
    Join Date
    Aug 2012
    This is insert coding so far but I got stuck here and I have problem to proceed.
    PHP Code:
    //this is using Malay language
    <script language="javascript">
    alert("Nama Pesakit <?php echo $_POST['idpesakit']; ?> sudah didaftarkan.");

    //If form not submitted, show form.
    if(!isset ($_POST['submit'])){
    <header>Tambah Pesakit</header>
    <title><h2>Tambah Pesakit</h2></Title>
    <form method="post" action="add.php">

    Nama: <input type="text" name="nama" /><br/>
    K/P Dokumen Diri: <input type="text" mode="text" name="kpdokumendiri" /><br/>
    Tarikh: <input type="int" name="tarikh" /><br/>

    <p />

    <input type="submit" name="submit" value="Simpan" />
    //If form submitted, respond to user.
    } else {


    //Check if user already exists

    $getUSer =mysql_query("SELECT(*) from bel_iza where butiran_pesakit='$nama'");
    $userExist mysql_fetch_type($getUSer);

    if (
    $userExist[0]>0) {
    $status "<font color=red>User already exist \"$nama\" .<br>Record is not save.</font>"
    $status ;
            } else {
    $addUser   mysql_query("INSERT INTO user (nama,kpdokumendiri,tarikh)
                    VALUES ('
                if (
    $addUser) {
                <header>Tambah Pesakit</header>
                <title><h2> Pesakit Sudah Ditambah </h2></Title>

    " onload=\"window.alert('Rekod Simpan!');\"";
    header('Location: display.php');
    "Record not save...some problems";




Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.16943 seconds
  • Memory Usage 2,972KB
  • Queries Executed 13 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (5)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (10)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates