Forum Moderators: coopster

Message Too Old, No Replies

PHP Redirect with If statement

Need Help with redirect with if statement

         

msmish

8:13 pm on Dec 15, 2003 (gmt 0)

10+ Year Member



Okay I know little to nothing about PHP. But I know how to code what I want in asp. What I have done is createed a form that allows the user to select a radio button and based on the button they select I do a redirect to another page from the current page. Here is the asp code.
___________________________________________________________
**** this is before the body***
<%
if Request.Form("ordertype")<>"" then
Response.Redirect(Request.Form("ordertype"))
end if
%>
<html>
**** this is in the body***
<form name="QuoteForm" method="post" action="quote.asp">
......
.....
<td colspan="3"><input type="radio" name="ordertype" value="quoteAS.asp">
<span class="style10"><strong>Screenprinting &amp; Embroidery
<br>
<input type="radio" name="ordertype" value="quoteSE.asp">
Advertising Specialties
</strong></span><br><br>
<input name="continue" type="submit" id="continue" value="Continue"></td>
__________________________________________________________
when working properly the form will post back to itself, execute the if statement and go to the appropriate page. HOW DO I DO THIS IN PHP?

dmorison

8:28 pm on Dec 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi msmish,

Firstly, variables from your form are accessed just as any other variable within your PHP script; so in your case, the variable $ordertype will hold the value you want to redirect based upon.

The PHP equivalent of a Response.Redirect is to use the header() [uk.php.net] function to set a location header, for example:

header("Location: /somepage.php");

or in your case...

header("Location: ".$ordertype);

The full stop in that code is the string concatenation operator.

Hope this helps!

msmish

9:52 pm on Dec 15, 2003 (gmt 0)

10+ Year Member



Is this the proper syntax..
<?
if $ordertype <>"" then
header("Location: ".$ordertype);
end if
?>

or do I have to use a $_POST["ordertype"]

and do I have to set values by using
in my form like this..
<input type="radio" name="ordertype" value="<?= $quoteAS.php?>">

or can it just be value="quoteAS.php"

NickCoons

11:35 pm on Dec 15, 2003 (gmt 0)

10+ Year Member



<Is this the proper syntax..
<?
if $ordertype <>"" then
header("Location: ".$ordertype);
end if
?>>

Try this:

<?php
if($ordertype!= "")
{
header("Location: " . $ordertype);
}
?>

<or do I have to use a $_POST["ordertype"]>

You will have to use this if "register globals" is turned off.

<and do I have to set values by using
in my form like this..
<input type="radio" name="ordertype" value="<?= $quoteAS.php?>">

or can it just be value="quoteAS.php">>

The latter is correct.

msmish

2:21 am on Dec 16, 2003 (gmt 0)

10+ Year Member



thanks to you both. Together both have help me to get the basics of my form. Could either of you recommend a good online tutorial on PHP for newbees.

NickCoons

3:37 am on Dec 16, 2003 (gmt 0)

10+ Year Member



The PHP site at [php.net...] is a wealth of information, is nicely laid-out, and is easy to read.