SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm a new to programming PHP. Currently, I'm more skilled in Cold Fusion. I want to know how to make a page change depending on what the user has submitted via form.

    For example.

    The first page is a FORM. The user is presented with 2 radio button options.

    ( ) a. Yes, I'd like to go to site1.com [value = 1]
    ( ) b. No, I'd like to go to site2.com [value = 2]

    When the user presses SUBMIT, they are taken to the second page which is what I use to process the information. Then the information is saved to the database. Depending on what the user picked, they are taken to another page. Also, the program should not go any further.

    If they choose a, they go to www.site1.com, otherwise they go to www.site2.com.

    How do I accomplish this in PHP?

    In Cold Fusion it was pretty simple:
    [cfif form.location is 1]
    [cflocation url="www.site1.com"]
    [cfabort]
    [cfelse]
    [cflocation url="www.site2.com"]
    [cfabort]
    [/cfif]

    If anyone has any ideas, let me know.

    Steven Samuel

  2. #2
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As long as you have no text sent out to the client before the redirect on the same page, you could use this:
    Code:
    header("Location: http://path.to/new/url");

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is in your form:
    <INPUT TYPE="RADIO" NAME="location" VALUE="sylow.net" checked > Site 1
    <INPUT TYPE="RADIO" NAME="location" VALUE="GreatKara.com"> Site 2

    This is your php code:
    //database code here
    <?
    header("Location: http://$location");
    ?>

    Great Dane
    Gokhan ARLI

  4. #4
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've gotten that far with using header by using this code:

    <?php
    if ($email == "") {
    header("Location: email_reminder_denied.php");
    exit;
    }
    ?>

    It's located at the top of my page. This works fine. But when I place the code down to where it needs to be, it gives me this error:

    Warning: Cannot add header information - headers already sent by (output started at /usr/local/www/docs/sohh.com/ohha2001/email_reminder_process.php:8) in /usr/local/www/docs/sohh.com/ohha2001/email_reminder_process.php on line 63

    This is the code:

    <?php
    if ($email == "") {
    header("Location: email_reminder.php");
    exit;
    }
    ?>

    <?php
    // This php is supposed to take information from email_reminder.php and
    // insert the information into the ohha2001 tbl_email_list database

    // set variable for emailsignupdate
    $emailsignupdate = gmdate("Y-m-d");

    // set variable for emaillist_ohha
    $emaillist_ohha = 1;

    // set variable for emailipaddress
    $emailipaddress = getenv("REMOTE_ADDR");

    // get common_db.inc
    include "common_db.inc";

    // connect to the ohha2001 database
    $link_id = db_connect('ohha2001');

    // set variable query to SQL statement
    // query checks to see if the users e-mail address is already in the database
    $select_query = "SELECT tbl_email_list.email FROM tbl_email_list WHERE tbl_email_list.email = \"$email\"";

    // combines the query to the datasource
    $result = mysql_query($select_query, $link_id);

    // set variable recordcount
    $recordcount = mysql_num_rows($result);

    // check to see if the e-mail address is already in the database
    if ($recordcount > 0) {

    echo ("<BR>e-mail address is already in the database");

    } else {

    // add information from previous page to the database table tbl_email_list

    $insert_query = "INSERT INTO tbl_email_list VALUES (NULL, '$email', '$emailsignupdate', '$emaillist_ohha', '$emaillist_sohh', '$emailipaddress', '$emailstyle')";

    // $ result = mysql_query($insert_query);

    // end
    header("Location: email_reminder_confirm.php");
    exit;
    }

    ?>

    If anyone has any ideas, or can tell me how I can optimize my code better, let me know. I'm just starting.

    Thanks

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is above the <?php line you cannot have any output including html or blank lines or spaces above that line or it will break your header() call
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know, I read that in a PHP book somewhere.

    My question is how can I do it? Is it impossible? Is there another function that I don't know about? Should I do it using JavaScript?


    <///////~

    www.sohh.com

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do it why don't you just stick all that code above the html? It would appear that nothing you showed in your code would be causing the error, so it must be above your opening <?php tag. Why can't you remove whats above that tag. Also make sure that their is no white space in your .inc files.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's the whole page. There is no HTML in the page. There aren't any HTML tags to be found. Strictly PHP code. I can send you the page via e-mail if you want to see it.

    <///////~

    www.sohh.com

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See in between the ?> and the second <?php that is whitespace and you cannot have it

    <?php
    if ($email == "") {
    header("Location: email_reminder.php");
    exit;
    }
    ?>

    <?php


    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •