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 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    $_POST not working!

    Hey

    My usageResult.php echos the $_POST('cat') and it doesnt work! Its just blank! I really cant understand why!!! PLEASE HELP!

    Here is the usageForm.php.

    Thanks SO SO SO SO MUCH!

    PHP Code:
    <html>
        <head> 
            <title>Usage Tracking</title> 
            <SCRIPT language=JavaScript>
            function reload(form) {
                var val=form.cat.options[form.cat.options.selectedIndex].value;
                self.location='UsageForm.php?cat=' + val ;
            }
            </SCRIPT>
        </head>
            
            <body>
            <h2>Usage Tracking</h2>
            <form action="UsageResult.php" method="post">
            Category : 
            <select name="cat" onchange="reload(this.form)">
            <option value="">-- All --</option>
          
            <?php
                $cat
    =$_GET['cat'];
                
                
    $connect mysql_connect('localhost''root''');
                if(!
    $connect) {  
                    die(
    'Could not connect: '.mysql_error());
                }
                
    mysql_select_db('phase3');
                
                
    $result mysql_query('
                    Select distinct description 
                    from category
                '
    );
                
                while(
    $row mysql_fetch_row($result)) { 
                    print 
    "<option value = \"$row[0]\" > $row[0] </option>";
                } 
                
                
    mysql_close($connect);
                
            
    ?>
            
            </select>
            
            </br>
            News Title :
            <select name="newsTitle">
            
          
            <?php
                $connect 
    mysql_connect('localhost''root''');
                if(!
    $connect) {  
                    die(
    'Could not connect: '.mysql_error());
                }
                
    mysql_select_db('phase3');
                
                if(!isset(
    $cat)) {
                    
    $result mysql_query("
                        Select distinct title 
                        from news_article
                    "
    );
                } else {
                    
    $result mysql_query("
                        select na.title
                        from news_article na,category c
                        where na.news_id = c.highlight_news_id
                          and c.description = '$cat'
                        
                        union
                        
                        select na.title
                        from news_article na,news_category nc,category c
                        where na.news_id = nc.news_id
                          and nc.category_id = c.category_id
                          and c.description = '$cat'
                    "
    );
                }
                
                
                while(
    $row mysql_fetch_row($result)) { 
                    print 
    "<option value = \"$row[0]\" > $row[0] </option>";
                }
                
                
    mysql_close($connect);
                
            
    ?>
            
            <input type="submit" value="Submit"/>
            </form>
            
            
            
            </body>
    </html>

  • #2
    New Coder
    Join Date
    Apr 2008
    Location
    Blagoevgrad, Bulgaria
    Posts
    47
    Thanks
    0
    Thanked 8 Times in 8 Posts
    Just test it with only this code inside UsageResult.php

    PHP Code:
    echo $_POST['cat']; 
    You may try to change usageResult.php to UsageResult.php
    Last edited by er4o; 04-02-2010 at 04:47 AM.

  • #3
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes... still doesnt work!

  • #4
    New Coder
    Join Date
    Apr 2008
    Location
    Blagoevgrad, Bulgaria
    Posts
    47
    Thanks
    0
    Thanked 8 Times in 8 Posts
    Edited my post ^^

  • #5
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah thats exactly what i am doing...
    and the file is named UsageResult.php

    I made a typo earlier..
    Thanks. But its still not working. I've been on this for three hours now!!

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    My usageResult.php echos the $_POST('cat') and it doesnt work! Its just blank! I really cant understand why!!! PLEASE HELP!
    Where's the code in usageResult.php?
    Last edited by abduraooft; 04-02-2010 at 10:29 AM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Its simply:

    PHP Code:
    <html>
        <body>
            <?php
                
    echo $_POST['cat'];
                     
    ?>
            </body>
    </html>

  • #8
    Regular Coder
    Join Date
    Jan 2009
    Posts
    193
    Thanks
    0
    Thanked 20 Times in 20 Posts
    To me it looks like you need to use $_GET because in the reload function you are placing the value in the url.

  • #9
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As in?
    I use echo $_GET('cat') in my UsageResult.php file and keep everything else the same?

    If i do so, I get this error
    Notice: Undefined index: cat in C:\wamp\www\Project\UsageResult.php on line 4

    This error disappears when i change echo $_GET('cat') to echo $_POST('cat')

    echo $_POST('cat') shows a blank.. Nothing appears. I can see the cat variable in the address bar though..
    Wish i could just grab it from there and put in on the webpage. lol.
    Last edited by rockinik; 04-03-2010 at 04:32 PM.

  • #10
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Here is the usageForm.php. [...]
    PHP Code:
    while($row mysql_fetch_row($result)) { 
                    print 
    "<option value = \"$row[0]\" > $row[0] </option>";
                } 
    Check the parsed html output of your page from browser's view source option and make sure that the <option> tags are getting the right values from DB.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #11
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yupp.. Everything is perfect. See Below:

    PHP Code:
    <option value "World" World </option><option value "Singapore" Singapore </option><option value "Asia-Pacific" Asia-Pacific </option><option value "Business" Business </option><option value "Sports" Sports </option><option value "Technology" Technology </option><option value "Entertainment" Entertainment </option><option value "Singapore News" Singapore News </option><option value "Business News" Business News </option><option value "Health" Health </option><option value "Politics" Politics </option><option value "Diet and Nutrition" Diet and Nutrition </option><option value "Disasters" Disasters </option
    This is copy pasted from the source code.

    OMG! I hope i can figure this out soon. My submission is in 24 hours time!


  •  

    Posting Permissions

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