Results 1 to 4 of 4

Thread: cannot get data to post to mysql with web form

  1. #1
    Join Date
    Nov 2009

    Exclamation cannot get data to post to mysql with web form

    I am trying to create something similar to a time clock. I have a web form that has several fields for integers. I want to be able to enter in these numbers and hit submit on my form and send off the data to the database I have created.

    For some reason when I press the submit button, nothing happens. What have I done wrong? Here is the code I have so far in my file cloudlog.php

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Flight Log</title>
    <style type="text/css">
    .container {
        margin: 0 auto;

    <div class="container">
    <form action="cloudlog.php" method="post">

      <table border="1" cellspacing="2" cellpadding="2">
          <th scope="col" width="75">SEL</th>
          <th scope="col" width="75">MEL</th>
          <th scope="col" width="75">Cross</th>
          <th scope="col" width="75">Day</th>
          <th scope="col" width="75">Night</th>
          <th scope="col" width="75">Act. Instr.</th>
          <th scope="col" width="75">Sim. Instr.</th>
          <th scope="col" width="75">Ground</th>
          <th scope="col" width="75">Dual Rec.</th>
          <th scope="col" width="75">Dual Given</th>
          <th scope="col" width="75">PIC</th>
          <th scope="col" width="75">FTD</th>
          <th scope="col" width="75">SIM</th>
          <th scope="col" width="75">SES</th>
          <th scope="col" width="75">MES</th>
          <th scope="col" width="75">Multi-Engine</th>
          <th scope="col" width="75">Total</th>
          <td><input name="sel" type="number" size="5" /></td>
          <td><input type="number" name="mel" size="5" /></td>
          <td><input type="number" size="5" name="crosscountry" /></td>
          <td><input type="number" size="5" name="day" /></td>
          <td><input type="number" size="5" name="night" /></td>
          <td><input type="number" size="5" name="actualinstrument" /></td>
          <td><input type="number" size="5" name="simulatedinstrument" /></td>
          <td><input type="number" size="5" name="groundschool" /></td>
          <td><input type="number" size="5" name="dualreceived" /></td>
          <td><input type="number" size="5" name="dualgiven" /></td>
          <td><input type="number" size="5" name="pilotincommand" /></td>
          <td><input type="number" size="5" name="ftd" /></td>
          <td><input type="number" size="5" name="sim" /></td>
          <td><input type="number" size="5" name="ses" /></td>
          <td><input type="number" size="5" name="mes" /></td>
          <td><input type="number" size="5" name="multiengine" /></td>
          <td><input type="number" size="5" name="total" /></td>
      <div align="center"><br />

      <input name="Submit" type="button" value="Submit to Logbook" />


    if (isset ($_POST["Submit"])){
    $con mysql_connect ("host","username","password");
    if (!
    $con) {
        die (
    "something went wrong... mySQL Error:" mysql_error());


    $sql "INSERT INTO logbook (SEL,MEL,CROSS,DAY,NIGHT,ACTUALINSTRUMENT,SIMULATEDINSTRUMENT,GROUNDSCHOOL,DUALRECEIVED,DUALGIVEN,PIC,FTD,SIM,SES,MES,MULTI,TOTAL) VALUES ('$_POST[sel]','$_POST[mel]','$_POST[crosscountry]','$_POST[day]','$_POST[night]','$_POST[actualinstrument]','$_POST[simulatedinstrument]','$_POST[groundschool]','$_POST[dualreceived]','$_POST[dualgiven]','$_POST[pilotincommand]','$_POST[ftd]','$_POST[sim]','$_POST[ses]','$_POST[mes]','$_POST[multiengine]','$_POST[total]')";





  2. #2
    Join Date
    Nov 2009
    So I got a little further. I was able to get it to work by changing the button type from "button" to "submit" however now when the page clears and I check my database nothing appears to have been saved.

  3. #3
    Join Date
    Jul 2013
    Voorheesville NY USA
    Start tracking your progress with echo statements and narrow down the possibilities

  4. #4
    Join Date
    Mar 2007
    Your problem #1 : <input type="number" size="5" name="total" />

    type is either text, hidden, button, submit, file or password.

    You also need to use mysql_real_escape_string() function to prepare your inputs too and you SHOULD NOT be using $_POST directly.

    You should have an array to sanitize the $_POST array in to and use the sanitized array to post your data.

    I whipped up this
    PHP Code:
    $con mysql_connect ("host","username","password") or die ("something went wrong... mySQL Error:" mysql_error());

    $fld = array('sel'=>'','mel'=>'','crosscountry'=>'','day'=>'','night'=>'','actualinstrument'=>'','simulatedinstrument'=>'',
    $fld as $key=>$fval ){
    $fld[$key] = "'".mysql_real_escape_string(clean($_POST[$key]))."'";
    $field[$key] = strtoupper($key);
    $sql "INSERT INTO logbook (" implode(",",$field).") VALUES('".implode("','",$fld)."');--";

    which is neither tested or guaranteed to work.

    the idea is to have an array of the field names as keys with no data and using it to fill with data that has been cleaned or sanitised and escaped at the same time using the secondary array to create an array of field names then using the load function to create a string for field names and full values sever the query can then be run.

    What you need is a function clean that will strip out things like slashes any extraneous spaces HTML characters that can be used to break the PHP script all for SQL injection.

    The script has not been tested as previously stated it is just an idea to help reduce the amount of code and allow you to manipulate field names if needed.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.09500 seconds
  • Memory Usage 2,913KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (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
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)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 (73):
  • 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_postinfo_query
  • fetch_postinfo
  • 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
  • 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