SitePoint Sponsor

User Tag List

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

    help with php/MySQL tutorial

    I'm receiving this Apache error message:

    Forbidden
    You don't have permission to access /< on this server.

    Apache/1.2.24 Server at 127.0.0.1 Port 80

    with the following page (mulitjoke.html) code:

    <HTML>
    <BODY>
    <?
    //if the user wishes to add a joke
    if (isset($addjoke)):
    ?>

    <FORM ACTION="<? echo($PHP_SELF); ?>" METHOD=POST>
    <P>Type your joke hereBR>
    <TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP></TEXTAREA><BR>
    <INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT">
    </FORM>

    <?
    //connect to the database server
    $dbcx = @mysql_connect("localhost", "", "");
    if (!dbcnx) {
    echo ( "<P>Unable to connect to the MySQL Server at this time.</P>");
    exit();
    }

    //select the jokes database
    if (! @mysql_select_db("jokes") ) {
    echo( "<P>Unable to locate the joke database at this time.</P>" );
    exit();
    }

    //if a joke has been submitted, add it to the database
    if ("SUBMIT" == $submitjoke) {
    $sql = "INSERT INTO Jokes SET " . "JokeText=;'$joketext', " . "JokeDate=CURDATE()";
    if (mysql_query($sql)) {
    echo ( "<P>Your joke has been added.</P>");
    } else {
    echo ( "<P>Error adding submitted joke: " . mysql_error() . "</P>");
    }
    }

    echo ( "<P>Here are all the jokes in our database: </P>");

    //Request the text of all jokes
    $result = mysql_query("SELECT JokeText FROM Jokes");
    if (!$result) {
    echo ( "<P>Error performing query: " . mysql_error() . "</P>");
    exit();
    }

    //Display the text of each joke in a paragraph
    while ($row = mysql_fetch_array($result) ) {
    echo ( "<P>" . $row["JokeText"] . "</P>");
    }

    //when clicked, this link will load this page with the joke submission form displayed
    echo ( "<P><A HREF='$PHP_SELF?addjoke=1'>" . "Add a joke!</A></P>");

    endif;

    ?>
    </BODY>
    </HTML>


    I can't figure this out. What do I need to do? Please help.

  2. #2
    SitePoint Wizard
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    2,617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's start with the error you are getting. This basically happens when you have not typed out the full URL to the page. For example http://localhost/project/ would not work, as opposed to http://localhost/project/index.php

    This leads me to your second problem. I see you named the file mulitjoke.html. The page should have a .php extension before the PHP-code will be interpreted. I would recommend changing it .

  3. #3
    SitePoint Member
    Join Date
    Apr 2002
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    re:

    If I change the file extension, the html form disappears. I have run other scripts successfully up till now, so I don't believe that to be the answer. As for the path, I'm just following the SitePoint tutorial on PHP and MySQL, and the code is theirs. So the FORM ACTION=<? echo($PHP_SELF); ?> works according to them.
    Is this possibly an Apache problem and not with the code? Thanks for your reply earlier, please continue if you have some more ideas.

  4. #4
    SitePoint Member
    Join Date
    Apr 2002
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile one more thing

    Again, thanks very much for the reply. As a beginner I appreciate any and all help! The browser path used is http://localhost/mulitjoke.php (or html)
    The code "appears", after another recheck, to be exactly copied from the tutorial mentioned earlier.

    That doesn't mean there aren't errors remaining, but the </ at the end of the Apache error message combined with the error log stating "Filename is not valid" makes me believe the php is not recognized in the FORM ACTION (even tried with the long tag <?php used).

    Help!

  5. #5
    SitePoint Wizard
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    2,617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe a silly question, but are you able to run other PHP scripts on the same server?

  6. #6
    SitePoint Member
    Join Date
    Apr 2002
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    re: your question

    yes, I should have mentioned that I have had NO problems with other scripts. The problem with this script appears to be in the FORM ACTION for some reason.
    Thanks! - Kirk

  7. #7
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    have you tried changing it to:

    PHP Code:
    <form action="<?=$PHP_SELF?>">
    If that doesn't work try downloading the code from the site (not sure if its still there) if that works you know that you have mis-written something.....


    Sarah
    Regular user

  8. #8
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Kirk,

    You will need to change this (line 31)
    PHP Code:
    $sql "INSERT INTO Jokes SET " "JokeText=;'$joketext', " "JokeDate=CURDATE()"
    remove the ';' after the JokeText=
    PHP Code:
    $sql "INSERT INTO Jokes SET " "JokeText='$joketext', " "JokeDate=CURDATE()"
    also add in the else: here (line 14)
    PHP Code:
    <? 
    else:
    //connect to the database server 
    $dbcx = @mysql_connect("localhost""""");
    Testing on my server works perfectly

    You will need to have this called multijoke.php now, the reason the form disappeared was the you had missed the [else] out so there wasn't anything for the php to so if the addjoke wasn't clicked.

    If you still get errors then I would start looking at apache

    Regards

    Sarah
    Regular user

  9. #9
    SitePoint Member
    Join Date
    Apr 2002
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Many thanks!

    Excellent - I've got it working, thanks to you! Thanks very much for your help

  10. #10
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    not a problem
    Regular user


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
  •