RE: [PHP] Multiple Form Submit Buttons

From: Date: Fri, 11 Oct 2002 15:43:14 +0000
Subject: RE: [PHP] Multiple Form Submit Buttons
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-119660@lists.php.net to get a copy of this message
[snip] I have been digging through the documentation for a while, but I can't find the answer to this ... If I have a form with multiple submit buttons, how can I tell in PHP which button was clicked? [/snip] Use a switch/case statement; switch($action) { case "Save": // query to insert saved elements only $qsave = "UPDATE tblArticle "; $qsave .= "SET title = '$title', "; $qsave .= "teaser = '$teaser', "; $qsave .= "body = '$body' "; $qsave .= "WHERE ID = '$aid' "; if(!($dbsave = mysql_query($qsave, $dbconnect))){ print("MySQL reports: " . mysql_error() . "<br>\n"); exit(); } break; case "Submit Article": //query to submit article $qsubmit = "UPDATE tblArticle "; $qsubmit .= "SET title = '$title', "; $qsubmit .= "teaser = '$teaser', "; $qsubmit .= "body = '$body', "; $qsubmit .= "type = '$type' "; $qsubmit .= "WHERE ID = '$aid' "; if(!($dbsubmit = mysql_query($qsubmit, $dbconnect))){ print("MySQL reports: " . mysql_error() . "<br>\n"); exit(); } Each of the buttons is named "action" and based on the value the script processes accordingly. HTH! Jay

« previous php.general (#119660) next »