www.webdeveloper.com
Results 1 to 3 of 3

Thread: Form submit page loading TWICE? (tearing my hair out)

  1. #1
    Join Date
    May 2008
    Posts
    6

    Angry Form submit page loading TWICE? (tearing my hair out)

    I'm completely stumped. The ONLY explanation in my mind is somehow the page is loading twice.

    I have a link to a deleteitem.php?id=x where the get variable, id is passed to a deletion function.

    In the function:
    PHP Code:

    function blah(stuff) {

    //some misc stuff unrelated (no mysql queries whatsoever)

          
    if($id === false) {
          
           
    $errors[] = "Valid delete id is required";
           return 
    false;
        }

        
        
    //check to see if id exists
        
    $r mysql_query("SELECT id FROM $table_name WHERE id = '$id'");
        
        if(
    $r === false) {
           
    $errors[] = "Could not check for id's existence.";
           return 
    false;
        }
        
        if(
    mysql_num_rows($r) < 1) {
           
    $errors[] = "Delete id ($id) does not exist.";
           return 
    false;
        }

           
    //now there's code to actually delete the item based on some
           //different circumstances 
    I decide to delete id 41, which I KNOW is in the database. I check it right before clicking on the link to this page.

    Now, here's the amazing thing. I load this page, and right up comes the error

    Code:
    Delete id (41) does not exist.
    I assume there's been some screw up with my logic, but lo and behold, (41) has been deleted from the database, even though the function returned without deleting anything!

    The only possible conclusion I can come up with is the page is somehow loading twice...It deletes normally, then somehow magically reloads and finds out that the requested deletion has already been performed. I can think of no other explanation and even this makes little sense. This is really driving me crazy. Any help would be greatly appreciated.

  2. #2
    Join Date
    Jan 2005
    Posts
    592
    you need to give more code than that. Where is the code where you delete the entry from the database and where is the code that ties the above code with the code where it deletes the entry?

  3. #3
    Join Date
    May 2008
    Posts
    6

    Thanks for your reply

    It's kind of complex, it's a bunch of conditionals that build a select query dynamically that determines if this is good for deletion.

    If so, it generates a simple delete query.

    But my point is...it returned (false). The code after a return statement is not executed (not in any language I know), but somehow it ended up deleted anyway!

    The only code that comes before, (after the global header file) is:

    PHP Code:
    if(!$is_admin) {

       echo 
    "<p class='error'>Only admins can view this page.</p>";

    }
    else {

       if(
    delete_from_table("prizes","id",true) === false) {
          
    $errors[] = "Could not delete...";
       }
       
       if(
    no_errors()) {
          echo 
    "done!";
       }


    It's not really relevant. The code after generates a qstring like:

    Code:
    DELETE FROM $table_name WHERE id = $id LIMIT 1
    And yes, it seems to generate the appropriate query string every time, when I tested it. And the code after THAT is just the formatted footer file.

    But how is it deleting if it hits a return statement before any MYSQL deletes, updates, or inserts? It would only make sense if the page loaded twice. Loaded once, performed the delete, loaded twice, couldn't delete.

    I have a faint memory of something kinda like this happening before and it had something to do with how I was handling redirects. Like one pointed to http:// and the other to http://www

    Honestly, I guess I could ignore this error, because the task is done either way. I just feel like an idiot here and don't feel comfortable shipping this until I figure out what's going on.
    Last edited by davidsakh; 02-21-2009 at 09:18 PM.

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



Recent Articles