html/php form help..?
- Started
- Last post
- 6 Responses
- scpgt
ok. so i've got a nice simple form for updating my sql database. on submit, it goes to "page2.php" a la $updateGoTo = "section4.php";
problem is, i'd like it to be able to goto a dif page depending on the input of one field..
so if 'id4' value is '2', it goes to page1.php
else it goes to page2.php
for instance.this has to be doable surely..(?)
- UndoUndo0
if($_POST['id4']=="2"){
header("Location: www.example.com/page1.php")…
} else{
header("Location: www.otherexample.com/page2.php...
}
- cosmo0
use if statement like undoundo mentioned.
I personally prefer switch statements:
switch ($_POST['id4'])
{
case 2:
header ("Location: page2.php");case 4:
header ("Location: page2.php");
}
- ldww0
cosmo, aren't you missing "break;" after each case?
i also find switch statements to be cleaner.
also, as a good rule, i like to put exit; after each header location just as a safe gaurd. sometimes it can execute code after the header before it actually redirects.
- cosmo0
aahh yes, I did miss the breaks. ldww good catch.
yes, switch statements are a lot cleaner.
- determinedmoth0
also, as a good rule, i like to put exit; after each header location just as a safe gaurd. sometimes it can execute code after the header before it actually redirects.
ldww
(Feb 13 06, 07:27)True that as I learnt the hard way.
- scpgt0
grand.
thanks kindly for the help people.. shall give it a whizz in a bit.