开发者

PHP autoforwarding

开发者 https://www.devze.com 2023-02-25 04:32 出处:网络
If my PHP page contains: <input type=\"submit\" name=\"add1\" value=\"Add Item\"> <input type=\"submit\" name=\"开发者_运维问答chgprice\" value=\"Change Price\">

If my PHP page contains:

<input type="submit" name="add1" value="Add Item">
<input type="submit" name="开发者_运维问答chgprice" value="Change Price">
<input type="submit" name="delete" value="Delete Item">
<input type="submit" name="main" value="Main">

as well as:

<?PHP
if($_POST['main'] == "Main"){
    header('Location: http://hidden.edu/~test/457/1/index.php');
}elseif($_POST['dspphp'] == "Display Source" && $_POST['srcpw'] == "srcpass"){
    $_SESSION['srcsite'] = "store.php";
    header('Location: http://hidden.edu/~test/457/1/source.php');
}elseif($_POST['add1'] == "Add Item"){
    header('Location: http://hidden.edu/~test/457/1/additem.php');
}elseif($_POST['chgprice'] = "Change Price"){
    header('Location: http://hidden.edu/~test/457/1/changeprice.php');
}
?>

It autoforwards to changeprice.php. I just don't understand why it autoforwards there, and doesn't to the others. I have tried moving it around in the page but nothing seems to help. I can open the page directly, and it works fine. If I change changeprice.php to, say, index.php it autoforwards there instead. Any ideas?

Thanks for the input.


Change:

}elseif($_POST['chgprice'] = "Change Price"){

to:

}elseif($_POST['chgprice'] == "Change Price"){


The problem is that ALL input fields are submitted. So you're getting all four of your submit button values.

What you want is:

<input type="submit" name="submit" value="Add Item" />
<input type="submit" name="submit" value="Change Price" />
<input type="submit" name="submit" value="Delete Item" />
<input type="submit" name="submit" value="Main" />

and on the server:

 switch($_POST['submit']) {
     case 'Add Item':
         ...
         break;
     case 'Change Item':
         etc...
         break;
     default:
         ....
 }
0

精彩评论

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