Question:

I Need Help with PHP code...

by  |  earlier

0 LIKES UnLike

hi all...please solve my simple problem...actually im making a php script for my web page and its not working....how would you make it if you have to enter two different words saperately in a text box and press submit using get method..and as a result, saperate page opens for saperate word....for example,if i enter YES in a text box and press submit, it opens page-1....then i go back ....and if i enter NO..then it opens page-2....

what would be the simplest php programming for that???

yes i can see that code but what code you put in if{} then(????) i mean code in php (if then) statement about page location???

<?php

if ($_GET['val']) {

if($_GET['val'] == "yes") {

//do this if it was yes(DO WHAT? WHAT IS THE CODE FOR MOVING TO PAGE-1)

} else {

//do this if it wasn't yes(DO WHAT? WHAT IS THE CODE FOR MOVING TO PAGE-2)

}

is there any command like (goto) in php??

 Tags:

   Report

3 ANSWERS


  1. The header function in php will give you problems if you have to submit other info in the header to the next page. A cleaner solution would be to use javascript to achieve this

    &lt;?php

    if($_GET[&#039;val&#039;] == &quot;yes&quot;)

    {

    echo &quot;&lt;SCRIPT language=\&quot;JavaScript\&quot;&gt;&quot;;

    echo &quot;&lt;!-- window.location=\&quot;yes_page.php\&quot;; //--&gt;&quot;;

    echo &quot;&lt;/SCRIPT&gt;&quot;;

    }

    if($_GET[&#039;val&#039;] == &quot;no&quot;)

    {

    echo &quot;&lt;SCRIPT language=\&quot;JavaScript\&quot;&gt;&quot;;

    echo &quot;&lt;!-- window.location=\&quot;no_page.php\&quot;; //--&gt;&quot;;

    echo &quot;&lt;/SCRIPT&gt;&quot;;

    }

    else

    {

    echo &quot;Choose yes or no&quot;;

    }

    ?&gt;


  2. There are many ways to accomplish what you mentioned. Here is one of them:

    Create a redirect page

    This page can be called anything, e.g. redirect.php

    &lt;?php

    $whereto = $_GET[ &#039;whereto&#039; ];

    switch( $whereto )

    {

    case &quot;yes&quot;:

    header( &quot;Location: page1.html&quot; );

    exit( 0 );

    case &quot;no&quot;:

    header( &quot;Location: page2.html&quot; );

    exit( 0 );

    case &quot;yada&quot;:

    header( &quot;Location: yada.html&quot; );

    exit( 0 );

    default:

    header( &quot;Location: error-bad-choice.html&quot; );

    exit( 0 );

    }

    ?&gt;

    On the page where user has to enter yes/no/whatever, create a form with method=get and action=redirect.php

  3. hope this helps...

    &lt;?php

    $answer = $_GET[&#039;val&#039;];

    if( $answer == &quot;YES&quot;)

    {

    header(&quot;Location: page1.php&quot;);

    }

    else

    {

    header(&quot;Location: page2.php&quot;);

    }

    ?&gt;

    // header is use to redirect to another page. with the specified location

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.