User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,136 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,783 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 970 | Replies: 5
Reply
Join Date: Nov 2006
Location: Bucharest
Posts: 59
Reputation: Eko is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Eko's Avatar
Eko Eko is offline Offline
Junior Poster in Training

Very strange

  #1  
May 8th, 2007
The following cod,when I press the SUBMIT button , I get "Forbidden, You don't have permission to access /< on this server."

<html>
<head>
<title> The Internet Joke Database </title>
</head>
<body>
<?php
  if (isset($_GET['addjoke'])): // If the user wants to add a joke
?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Type your joke here:<br />
<textarea name="joketext" rows="10" cols="40" wrap>
</textarea><br />
<input type="submit" name="submitjoke" value="SUBMIT" />
</p>
</form>
<?php
  else: // Default page display

    // Connect to the database server
    $dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');
    if (!$dbcnx) {
      die( '<p>Unable to connect to the ' .
           'database server at this time.</p>' );
    }

    // Select the jokes database
    if (! @mysql_select_db('jokes') ) {
      die( '<p>Unable to locate the joke ' .
           'database at this time.</p>' );
    }

    // If a joke has been submitted,
    // add it to the database.
    if (isset($_POST['submitjoke'])) {
      $joketext = $_POST['joketext'];
      $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 the jokes
    $result = @mysql_query('SELECT JokeText FROM Jokes');
    if (!$result) {
      die('<p>Error performing query: ' .
          mysql_error() . '</p>');
    }

    // 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="' . $_SERVER['PHP_SELF'] .
         '?addjoke=1">Add a Joke!</a></p>');

  endif;

?>
</body>

</html>
The funny thing is that 2 month ago,the same code , on the same machine worked.
Now I tried on a different pc,I install/unistall dozens of wamp versions , I don't have a clue what could be wrong
As the code says,I'm running it on the same computer ( localhost )
Last edited by Eko : May 8th, 2007 at 6:53 pm.
"Get rich or die tryin"(50-cent)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation: johny_d is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
johny_d's Avatar
johny_d johny_d is offline Offline
Junior Poster in Training

Re: Very strange

  #2  
May 8th, 2007
That's because you try to use short_open_tag (<? instead of <?php ) as your php openning tag in [php]<form action="<?=$_SERVER['PHP_SELF']?>" method="post">[/php] while you probably have it set in your php.ini to off:
short_open_tag = Off

That's why, when you run the script, your form looks like this:
[php]<form action="<?=$_SERVER['PHP_SELF']?>" method="post">[/php] instead of [php]<form action="/path_to_your_file.php" method="post">[/php] hence the error.

On your previous server (configuration) (2 months ago), you probably had short_open_tag = On , and that's why the same script worked.

Php reccomends in php.ini to avoid using short_open_tag in your scripts, exactly beacuse of this. On some servers this option is not enabled and you get in a lot of trouble, the way you did.

So, to solve your problem, try to use:
[php]<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">[/php]
Last edited by johny_d : May 8th, 2007 at 7:36 pm.
Reply With Quote  
Join Date: Nov 2006
Location: Bucharest
Posts: 59
Reputation: Eko is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Eko's Avatar
Eko Eko is offline Offline
Junior Poster in Training

Re: Very strange

  #3  
May 9th, 2007
Hey thanks It worked . You we're right ,it was that short_hand thing.

You're the best
"Get rich or die tryin"(50-cent)
Reply With Quote  
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation: johny_d is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
johny_d's Avatar
johny_d johny_d is offline Offline
Junior Poster in Training

Re: Very strange

  #4  
May 9th, 2007
You're most welcome
Reply With Quote  
Join Date: Apr 2005
Location: Old Hampshire, Old England (LOL)
Posts: 11,937
Reputation: jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough 
Rep Power: 30
Solved Threads: 268
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Microsoft Fanboy

Re: Very strange

  #5  
May 9th, 2007
I think the reason it worked then didnt is did you upgrade?

a new version (i myself use XAMPP) came out recenly and the same thing happened to me. Seems they turned off the short tags as its the new default behaviour?
TRY MY SUGGESTIONS AT YOUR OWN RISK!
james.bennet1@ntlworld.com
Reply With Quote  
Join Date: Nov 2006
Location: Bucharest
Posts: 59
Reputation: Eko is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Eko's Avatar
Eko Eko is offline Offline
Junior Poster in Training

Re: Very strange

  #6  
May 9th, 2007
I've used wamp 1.5.0 , 1.5.0.a , 1.7.1 , 1.4.2
All of them have the short_open_tag = Off by default , and I guess that all future versions will have this as well
It can be really frustrating.
They should ask you when u install it , if you want short tag on/off
Last edited by Eko : May 9th, 2007 at 7:55 pm.
"Get rich or die tryin"(50-cent)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:47 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC