Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: problem

  1. #1
    New Coder
    Join Date
    Aug 2003
    Location
    Belgium
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem

    I made a script:

    Code:
    <form>
    <SELECT name="test">
    <OPTION value="1">1</OPTION>
    <OPTION value="2">2</OPTION>
    <OPTION value="3">3</OPTION>
    </SELECT><BR></form>
    PHP Code:
    <? if ($_POST['test'] = ) {
     
       
    $template "ATGtemp";
    include(
    "/home/virtual/site51/fst/var/www/html/news2/show_news.php");
     }
    else {
      echo 
    "testtest";
    }
    ?>
    these 2 codes are in 1 file.

    I always get include() and I never get "testtest"
    What do I have to change in the script so it wont always show include() ???
    g0liatH

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    if ($_POST['test'] = 
    is most certainly a typo. What you are doing there is assigning the number 2 to $_POST['test'] by using one equals sign. This assignment always succeeds, so it evaluates as true. What you need is to use two equals signs to compare for equality:

    PHP Code:
    if ($_POST['test'] == 
    If you happen to make this mistake often, here's a trick that works the same as the above code, but if you use one equals sign you get a PHP error:

    PHP Code:
    if (== $_POST['test']) 
    De gustibus non est disputandum.

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    I'm not sure how you even get that. Your expression in your if statement is incorrect

    if ($_POST['test'] = 2

    should probably be

    if ($_POST['test'] == "2")
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And if you define your form tag without the method="post" attribute, all incoming form data will be by GET, and thus in the $_GET array.
    De gustibus non est disputandum.

  • #5
    New Coder
    Join Date
    Aug 2003
    Location
    Belgium
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok thx guys I kno im a n00b
    g0liatH

  • #6
    New Coder
    Join Date
    Aug 2003
    Location
    Belgium
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I used the script now and it works but there is still 1 problem.
    If i click "post comment", the script goes back to the first page

    you can see it yourself here:
    http://www.alltimegaming.com/phptest/testform2.php
    and if I click the submit button again, it works...

    this is the new code:

    Code:
    <form method="post">
    <SELECT name="test">
    <OPTION value="1">Show All</OPTION>
    <OPTION value="2">General</OPTION>
    <OPTION value="3">Gaming</OPTION>
    <OPTION value="4">Site</OPTION>
    <OPTION value="5">Events</OPTION>
    </SELECT><BR>
    <input type="submit" value="Submit">
    </form>
    <? if ($test == 1 ) {
    $template = "ATGtemp";
    include("/home/virtual/site51/fst/var/www/html/news2/show_news.php");
    }
    elseif ($test == 2 ) { 
     $template = "ATGtemp";
       $category= "3";
     include("/home/virtual/site51/fst/var/www/html/news2/show_news.php");
    }
    elseif ($test == 3 ) { 
     $template = "ATGtemp";
       $category= "4";
     include("/home/virtual/site51/fst/var/www/html/news2/show_news.php");
     }
     elseif ($test == 4 ) { 
     $template = "ATGtemp";
       $category= "5";
     include("/home/virtual/site51/fst/var/www/html/news2/show_news.php");
     }
     elseif ($test == 5 ) { 
     $template = "ATGtemp";
       $category= "6";
     include("/home/virtual/site51/fst/var/www/html/news2/show_news.php");
     }
    
     ?>
    Do u know what the problem is? Is there a else {} command to continue the link?
    Last edited by g0liatH; 11-12-2003 at 05:53 PM.
    g0liatH

  • #7
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    <form method="post">
    <SELECT name="test">
    <OPTION value="1">Show All</OPTION>
    <OPTION value="2">General</OPTION>
    <OPTION value="3">Gaming</OPTION>
    <OPTION value="4">Site</OPTION>
    <OPTION value="5">Events</OPTION>
    </SELECT><BR>
    <input type="submit" value="Submit">
    </form>
    <?php

    $test 
    $_POST['test'];

    if (
    $test == ) {
        
    $template "ATGtemp";
        include(
    "/home/virtual/site51/fst/var/www/html/news2/show_news.php");
    }
    ..... 
    etc    etc      etc ..........

  • #8
    New Coder
    Join Date
    Aug 2003
    Location
    Belgium
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It doesn't help. I still have to click submit until I can post a comment
    g0liatH

  • #9
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I dunno where your problem is, I don't even see a post comment on that form or code you're showing

  • #10
    New Coder
    Join Date
    Aug 2003
    Location
    Belgium
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you click on gaming or show all or whatever, you see news, and on every newspost u see "comments", if you click on that, you just go to a white page instead of the page u should go and if u then click submit, u go to the real page.
    g0liatH

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you mean by "Post Comment" the link titled "comments", then you get the data per GET parameters. Links are not forms and their query string does not appear in the $_POST array. Does that help?
    De gustibus non est disputandum.

  • #12
    New Coder
    Join Date
    Aug 2003
    Location
    Belgium
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yea i mean the link "comments". so u are saying I have to change
    <form method="post"> to <form method="get">
    ?
    g0liatH

  • #13
    New Coder
    Join Date
    Aug 2003
    Location
    Belgium
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    w00t finally it works!!

    thx everyone who helped me
    g0liatH


  •  

    Posting Permissions

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