开发者

I need to get form data from multiple forms on one page using $_POST

My project is a menu that displays daily specials at a cafe. The Pointy Haired Boss(PHB) needs to add/remove items from the menu on a daily basis,

so I stored all dishes with MySQL, and created a page which will load all menu items as buttons. When clic开发者_开发知识库ked, the button will UPDATE the item, turning it on or off.

I need form data to detect which button was pressed, so my query knows which $menuItem to UPDATE. That is the purpose of the hidden fields.

<html><head></head>
<body>

<html><head></head>
<body>
<?php include("getElement.php");
$keys = array_keys($_POST);
echo $keys[0];
echo $keys[1];
//if(isset($_POST["menuItem"])){
//toggleItem($_POST["menuItem"]);
//echo print_r(array_keys($_POST));}
?>


<form name="b" action="scratchpad.php" method="post" > 
<input type="hidden" name="b" value="Cajun Gumbo"/> 
<input type="submit" style="color:blue" value="Cajun Gumbo" /> </form>

<form name="a" action="scratchpad.php" method="post" > 
<input type="hidden" name="a" value="Guacomole Burger"/> 
<input type="submit" style="color:blue" value="Guacomole Burger" /> </form>


</body> 
</html>

Can I get $_POST to identify which button was pressed? I get this error: Undefined offset: 1 in /home/ubuntu/public_html/scratchpad.php on line 10


not this way ;)

try this:

<form name="b" action="scratchpad.php" method="post" > 
<input type="hidden" name="b" value="Cajun Gumbo"/> 
<input name="one" type="submit" style="color:blue" value="Cajun Gumbo" />
<input name="two" type="submit" style="color:blue" value="Guacomole Burger" /> 

 </form>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜