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 4 of 4

Thread: newbee problem

  1. #1
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post

    newbee problem

    Hi i am new to php and was practising loops from the tutorial site http://devzone.zend.com/node/view/id/635
    But i got into a problemwhen i run my code
    Why does the following error message come?
    Forbidden

    You don't have permission to access /TestSite/method="post" on this server.
    Apache/2.0.63 (Win32) PHP/5.2.11 Server at localhost Port 80
    i cant figure it out.. The other programs use the same "POST" method to get their variables but why does this program return an error? If i run the tutorial code whch uses the same post method it works but not mine
    please help me
    i did the coding and here is my code

    PHP Code:
    <head>
    <title>Untitled Document</title>
    </head>

    <body>

    <form action=<?php $_SERVER['PHP_SELF'?> method="post">
    Enter the number of Rows <input name="rows" type="text" value="3" /> and Coloumn <input name="coloumn" type="text" value="3" /> <input name="submit" type="submit" value="submit" /></form>

    <?php

    if (isset($_POST['submit'])) {
        echo 
    "<table width = 90% border = '1' cellspacing = '5' cellpadding = '0'>";
        for (
    $r 1$r <= $_POST['rows']; $r++) {
            echo 
    "<tr>";
            for (
    $c 1$c <= $_POST['columns'];$c++) {
                echo 
    "<td>&nbsp;</td> ";
            }     echo 
    "</tr> ";
        }
        echo 
    "</table> ";
    }

    ?>
    </body>
    </html>
    here is the tutorials code
    PHP Code:
    <html> 
    <head></head>
    <body> 

    <?php 
    // check for submit 
    if (!isset($_POST['submit'])) { 
        
    // and display form 
        
    ?> 

        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> 
        <input type="checkbox" name="artist[]" value="Bon Jovi">Bon Jovi 
        <input type="checkbox" name="artist[]" value="N'Sync">N'Sync 
        <input type="checkbox" name="artist[]" value="Boyzone">Boyzone 
        <input type="checkbox" name="artist[]" value="Britney Spears">Britney Spears 
        <input type="checkbox" name="artist[]" value="Jethro Tull">Jethro Tull 
        <input type="checkbox" name="artist[]" value="Crosby, Stills & Nash">Crosby, Stills & Nash 
        <input type="submit" name="submit" value="Select"> 
        </form> 

    <?php 
        

    else { 
        
    // or display the selected artists 
        // use a foreach loop to read and display array elements 
        
    if (is_array($_POST['artist'])) { 
            echo 
    'You selected: <br />'
            foreach (
    $_POST['artist'] as $a) { 
               echo 
    "<i>$a</i><br />"
                } 
            } 
        else { 
            echo 
    'Nothing selected'
        } 

    ?> 

    </body> 
    </html>
    Last edited by adarshakb; 10-19-2009 at 07:25 AM.
    Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

    Albert Einstein
    -----------------------------------------------------
    My Blog songs

  • #2
    Regular Coder
    Join Date
    Dec 2006
    Location
    In the wilderness
    Posts
    106
    Thanks
    9
    Thanked 5 Times in 5 Posts
    PHP Code:
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    Your missing the echo function, plus you don't have quotes around the action attribute neither. That could be it?
    "The advantage of computers is that they do exactly what you tell them to do. The disadvantage of computers, on the other hand, is that they do exactly what you tell them to do."

    Excellent resource for learning PHP here

  • #3
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post
    Quote Originally Posted by karlosio View Post
    PHP Code:
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    Your missing the echo function, plus you don't have quotes around the action attribute neither. That could be it?
    yep that was the problem but got a new problem after i fixed that one .. misspelled coloumn
    thanks
    Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

    Albert Einstein
    -----------------------------------------------------
    My Blog songs

  • #4
    Regular Coder
    Join Date
    Dec 2006
    Location
    In the wilderness
    Posts
    106
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by adarshakb View Post
    yep that was the problem but got a new problem after i fixed that one .. misspelled coloumn
    thanks
    Yep thats due to this line

    Code:
    Enter the number of Rows <input name="rows" type="text" value="3" /> and Coloumn <input name="coloumn" type="text" value="3" /> <input name="submit" type="submit" value="submit" /></form>
    In you haven't figured it, It should be:

    Code:
    Enter the number of Rows <input name="rows" type="text" value="3" /> and Coloumn <input name="columns" type="text" value="3" /> <input name="submit" type="submit" value="submit" /></form>
    if you look in the PHP script you will see the following variables known as POST superglobals

    PHP Code:
    $_POST['rows'];
    $_POST['columns']; 
    These POST superglobals are getting whatever is posted to the server via the HTML form, its looking for the field names in the form under name="field" and places them inside a array so you access it via PHP eg $_POST['field'] (field name in square brackets with quotes) and these names have to be exactly the same as what is in the name attribute on the form. Hope that helps.
    "The advantage of computers is that they do exactly what you tell them to do. The disadvantage of computers, on the other hand, is that they do exactly what you tell them to do."

    Excellent resource for learning PHP here


  •  

    Posting Permissions

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