I have been trying for about a month now to get two submit buttons to work independently in PHP on the same page. I have found examples using text boxes but unfortunately my page has drop downs that use the _$POST array.
I for some reason cannot figure out how to code the switch case statement properly. Any ideas out there?
Here is the code for the PHP page:
(process.php)
And here is the code for the HTML pageCode:<?php error_reporting(E_ALL ^ E_NOTICE) ; if($_POST['item']) $item = $_POST['item']; // print_r ($_POST['item']); else $item = 2010; print_r ($_POST[item]); if($_POST['item2']) $item2= $_POST['item2']; else $item2 = 2009; ?> <?php // branch on the basis of 'Select1' value switch ($_POST['item']) { // if Select1 => add case 'Submit': // print_r $_POST['Select1']); $url = "<img src='/WXRECORDS/images/{$item}.png' />"; break; // if Select1 => subtract case 'Submit2': // print_r $_POST['Select1']); $url = "<img src='/WXRECORDS/images/{$item2}.png' />"; break; } ?> <?php $url = "<img src='/WXRECORDS/images/{$item}.png' />"; include_once('portland.html'); ?>
(portland.html)
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Portland Climate Data</title> <link href="stylesheets/public.css" rel="stylesheet" type="text/css" > </head> <body style="height: 53px; color: #FFFFFF; background-color: #000000;"> <form action="process.php" method="post"> <div id="banner" class="banner">Portland Oregon Climate Data </div> <div id="header" class="header" style="height: 35px; width: 300px" align="center"> <!DROP DOWN #1> <select name="item" style="width: 55px"> <?php for($i=2010; $i>=2006; $i--){?> <option value="<?php echo $i?>" <?php if($i==$_POST['item']) echo 'selected="selected"'?>><?php echo $i?></option> <?php }?> </select>   <!BUTTON #1> <input name="Submit1" type="submit" value="submit" style="height: 28px" /> <!DROP DOWN #2> <select name="item2" style="width: 65px"> <?php for($i=2010; $i>=2006; $i--){?> <option value="<?php echo $i?>" <?php if($i==$_POST['item2']) echo 'selected="selected"'?>><?php echo $i?></option> <?php }?> <!BUTTON #2> <input name="Submit2" type="submit" value="submit" style="height: 28px" /> </select> </div> <br /> </form> <div id="content" align="center" class="content"><?php echo $url ?></div> </body> </html>
I must admit I am embarrassed that I still have not figured out this code. I dont know why its so difficult for me. Tons of tutorials have not done the trick.


Reply With Quote

Bookmarks