Results 1 to 4 of 4

Thread: Weird POST behavior - only works on refresh

  1. #1
    Join Date
    Mar 2008

    Weird POST behavior - only works on refresh

    I've just uploaded my production site to Go Daddy so I can get it testing on the actual server, etc... I've run into a bug that I can't figure out for the life of me. Here's what's happening:

    I'm allowing users to input a "project" consisting of four fields: project name, project category, project date, and project description. From the first page, it takes their information submitted through POST into a second page where it displays the information they submitted for confirmation. So far, nothing has been put into the database. Upon pressing "Submit" on the confirm page, it again sends their info through POST (this time as hidden fields) to the final page where the query runs that puts it into the database. Here's the code:

    The script on the confirmation page:
    PHP Code:
    function postProjDetails() {

    //create short variable names

    $proj_name $_POST['proj_name'];
    $proj_cat $_POST['projectcat'];
    $proj_date $_POST['proj_date'];
    $desc $_POST['proj_desc'];

    //draw form containing project details and submit form.  This form calls an action on the next page to actually submit the project.  The function passes the user submitted values as hidden fields so as to pass via post to the actual submit function.

    <form action="post_submit.php" method="post">
    <input name="proj_name" type="hidden" value="<?php echo $proj_name?>" />
    <input name="projectcat" type="hidden" value="<?php echo $proj_cat?>" />
    <input name="proj_date" type="hidden" value="<?php echo $proj_date?>" />
    <input name="proj_desc" type="hidden" value="<?php echo $desc?>" />

    <p>Confirm your project details:</p>
    <p>Project Name: <?php echo $proj_name?></p>
    <p>Project Category: <?php echo $proj_cat?></p>
    <p>Project Date: <?php echo $proj_date?></p>
    <p>Project Description: <?php echo $desc?></p>

    <input name="Submit" type="submit" value="Submit" />


    As of this point, everything is displaying fine. Information has passed as expected from page 1 to page 2.

    The script on the final page that actually executes the query:

    PHP Code:
    function submitProj($user_id$user_type) {

    //create short var names

    $proj_name $_POST['proj_name'];
    $proj_cat $_POST['projectcat'];
    $proj_date $_POST['proj_date'];
    $desc $_POST['proj_desc'];

    $query "insert into projects values (NULL, '".$user_id."', '".$proj_name."', '".$proj_cat."', '".$proj_date."', '".$desc."', '".$user_type."')";
    $result mysql_query($query);

    if (!
    'Sorry, there was a problem entering your project into the database.  The error was '.mysql_error();
    'Done!  Your project is now in the database!';

    The problem is, when it gets to the third page, it doesn't have the info they submitted - it simply passes through as blank. That is, UNLESS I hit refresh. Then, it resends the info and everything works as it should. Obviously, I don't want the user having to refresh everytime they want to submit something. Anything jump out that might be the problem?

    Thanks ya'll!

  2. #2
    Join Date
    Feb 2007
    Could you post more of the 3rd page so we can get a better idea of how the page is functioning.

    Have you tried just printing the post variables to screen to see if its a problem with them or the vriables being added to the query string?

  3. #3
    Join Date
    Mar 2008
    Sure, no problem. Here's the actual page that calls the function I posted above:

    PHP Code:

    $page_title 'Project Submitted!';



    // Begin center content
    <div id="contentwell"> 

    <p>Post a project</p>

    <div id = "current_proj">
    <p>Your Current Projects</p><hr />
    <?php myCurrentProj($user_id); ?>
    <div id = "confirm">
    <?php submitProj($user_id$user_user_type); ?> <!-- just for your information, these variables are set via a function that loads global variables according to whichever user is logged in at the time. -->

    <!-- end #container --></div>

    I've tried printing the vars, and the same thing happens. Basically, the first time I submit, they come up empty. If I hit refresh, they fill in correctly.

    I'm thinking it may have something to do with variable scope. I've fixed the problem for now by using $_SESSION['var'] instead of $_POST['var'] but I'd still like to know why the latter is being screwy.

    Thanks much.

  4. #4
    Join Date
    Feb 2007
    hmm that is weird.

    Have you tried using $_REQUEST instead of $_POST, shouldnt make a difference. But wont hurt to try. Also try submitting the form using GET to see if the same issue occurs with the querystring.

    When you were printing the $_POST data, did you print inside the function?
    You could try assigning the variables outside the function, then give them global scope inside the function.

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.13972 seconds
  • Memory Usage 2,878KB
  • Queries Executed 13 (?)
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
  • (3)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 (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