How do you make a form send the input to the action and update MySQL at the same time?

Mar 12th, 2009 | By KC | Category: My SQL Related

I have a form which we wish to send a variables to an additional website with a movement option, WHILE updating my MySQL server somehow. Is which possible? If so, How?

Tags: , , ,

One comment
Leave a comment »

  1. have a redirect page in the middle, say if your using php have your form direct to formRedirect.php that looks like

    <?php
    //set these to determine whether form sent correctly
    $errorFirstValue = TRUE; //if an error
    $errorSecondValue = TRUE; //if an error

    if(!empty($_POST['firstValue'])){
    $firstValue= $_POST['firstValue'];
    $errorFirstValue = FALSE; //no error for firstValue
    }

    if(!empty($_POST['secondValue'])){
    $secondValue= $_POST['secondValue'];
    $errorSecondValue = FALSE; //no error for secondValue
    }

    //If there are any errors on how you want the page filled out send to original form page
    if($errorFirstValue && $errorSecondValue){
    header("LOCATION: backtowhateveerpageyoucamefrom.php");
    exit();
    }
    else{
    $updateTable = "UPDATE table SET firstValue='$firstValue' WHERE secondValue='$secondValue'";
    @mysql_query($updateTable);

    header('LOCATION: pagetoforward.php?firstValue=' . $firstValue . '&secondValue=' . $secondValue);
    exit();
    }

    ?>

    What you do is check the information submitted anyway you want (if its supposed to be a specific type or style use your reg exp) then attach the values to the end of the string your having forwarded to and use a $_GET[''] to get them. If the form is filled out incorrectly use an $error or $valid variable or something of that nature to test what should be submitted, and if it is an error or not valid send back to the original form

Leave Comment