SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    May 2002
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    header location not working?

    My first post! Need a little help on a very simple script.
    PHP Code:
    <?php

    $host 
    "yada";
    $user "blah";
    $database "blahblah";

    $id mysql_connect($host,$user);
    mysql_select_db($database$id);

    //while (list ($key, $val) = each ($HTTP_POST_VARS)) {
    //    echo "<br>$key: $val";
    //}

    $title=$HTTP_POST_VARS["title"];
    $startDate=$HTTP_POST_VARS["startDate"];
    $endDate=$HTTP_POST_VARS["endDate"];
    $description=$HTTP_POST_VARS["description"];
    $address=$HTTP_POST_VARS["address"];
    $city=$HTTP_POST_VARS["city"];
    $state=$HTTP_POST_VARS["state"];
    $zip=$HTTP_POST_VARS["zip"];
    $phone=$HTTP_POST_VARS["phone"];
    $email=$HTTP_POST_VARS["email"];
    $web=$HTTP_POST_VARS["web"];

    $sql "INSERT INTO calender(ID,title,startDate,endDate,description,address,city,state,zip,phone,email,web) VALUES('','$title','$startDate','$endDate','$description','$address','$city','$state','$zip','$phone','$email','$web')";
    $result mysql_query($sql);


    Header("Location: view.php");

    ?>
    The above code does NOT forward to view.php after everything else is finished. Doesn't return an error - doesn't do anything. Just stays on the current (blank) page.

    Also, is there a better way to assign values to each of my post vars?
    If I don't declare them like this:
    $web=$HTTP_POST_VARS["web"];
    then I can't refer to them by name. Example, I can't use the variable $web unless I declare it as above -- even though it was passed as a post var with the name of web already?

    Hmmm...

    Thanks everyone

    EDIT: I'm using "Small HTTP Server" and PHP 4 on windows 98, if that helps.
    Last edited by phpGrasshopper; May 9, 2002 at 13:24.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try use header() with a lowercase 'h'. an easier way to get all your variables set would be to do this.
    PHP Code:
    //php >= 4.1.0
    extract($_POST);

    //php < 4.1.0
    extract($HTTP_POST_VARS); 
    basically the extract funtion takes in an array, and will create variables based on each key in the array. if you look up the extract() funtion in the php manual, you will see that you can add prefixes to the variables as well if needed. extract is one the best functions IMO.

  3. #3
    SitePoint Member
    Join Date
    May 2002
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    extract() works great Thanks.

    Lower case header still won't work. Any other ideas?

  4. #4
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not sure what is wrong, but one thing...you need to have a password in your db connection.
    PHP Code:
    $id mysql_connect($host,$user,$password); 
    That might help ya...


    Sketch
    Aaron Brazell
    Technosailor



  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    make sure that there is nothing printed to the browser before it gets to the header() line. no html or prints. maybe that's it?

  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by rect
    make sure that there is nothing printed to the browser before it gets to the header() line. no html or prints. maybe that's it?
    But he said there was no error. If there was no error then it couldn't be a header problem. Most likely his query never executed because the db connection was a dud and that would cause the script to simply die.

    Sketch
    Aaron Brazell
    Technosailor



  7. #7
    SitePoint Member
    Join Date
    May 2002
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, the connection works fine...and it is inserting data into my table, so it can't be that?

    Maybe the server software doesn't support redirects or something? What free PHP server software do you folks use?

  8. #8
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Sketch
    But he said there was no error
    He/she may have PHP setup to log errors instead of displaying them

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  9. #9
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by phpGrasshopper
    Maybe the server software doesn't support redirects or something? What free PHP server software do you folks use?
    the header() function sends instructions to the browser, so it doesn't rely on the server for that. i use apache for my webserver and it is free, so you can check that out.

  10. #10
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by rect
    an easier way to get all your variables set would be to do this.
    PHP Code:
    //php >= 4.1.0
    extract($_POST);

    //php < 4.1.0
    extract($HTTP_POST_VARS); 
    using extract() totally defeats the purpose of accessing your variables via the arrays and not using register_globals. any variable that a user adds to the URL, etc. will be introduced as a variable in your script. i think it's much better to do it the way he was doing it, as HE controls what variables are created in the script, not the user. the only thing i would do is use references, since it's faster:

    PHP Code:
    $title = &$HTTP_POST_VARS['title']; 
    etc.



    Originally posted by phpGrasshopper
    What free PHP server software do you folks use?
    Apache.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR


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
  •