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

Question by Jared W.: How do you make a form send the input to the action and update MySQL at the same time?
I have a form that I want to send its variables to another website with the action option, WHILE updating my MySQL server somehow. Is that possible? If so, How?

Best answer:

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

//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

What do you think? Answer below!

Revisions

There are no revisions for this post.

Tags: , , , , , , ,

No comments yet.

Leave a Reply