mk10
mk10

Reputation: 9

$_POST don't give any result

I try with a little script on php but it doesn't give any result.

example.html:

<form action="action.php" method="post">
 <p>URL <input type="text" name="url"></p>
  
 <p><input type="submit" value="OK"></p>
</form>

action.php:

<html>
  <? echo $_POST['url'];?>
</html>

Even when the field of url is full, it doesn't give any result.

Upvotes: 0

Views: 87

Answers (3)

dlporter98
dlporter98

Reputation: 1630

First be sure that action.php is located in the same directory as the html file containing the form.

Second, change your php code to the following:

<?php echo $_POST['url']; ?>

Regarding short tags:

When PHP parses a file, it looks for opening and closing tags, which are which tell PHP to start and stop interpreting the code between them.

PHP also allows for short open tag http://php.net/manual/en/language.basic-syntax.phptags.php

Short tags example:

<? echo $variable ?>
<?= $variable ?>

These do not contain the opening "<?php" and is discouraged per the quote above.

However, starting in 5.4 the second version of the short tags will always be on regardless of the short tag setting in the php.ini. That means the

 <?= $variable ?>

will always be available.

How to use short tags prior to PHP 5.4

Open you php.ini file, search for "short_open_tag" and change the value to "1". http://php.net/manual/en/ini.core.php#ini.short-open-tag

Upvotes: 2

Mohammed Elhag
Mohammed Elhag

Reputation: 4302

change this :

 <html>
 <? echo $_POST['url'];?>
 </html>

by this :

<html>
<?php echo $_POST['url'];?>
</html>

UPDATE : to enable php short tags fast , at .htaccess the put the following :

php_flag short_open_tag on

Upvotes: 0

Mxx persian
Mxx persian

Reputation: 105

you should use <?php echo $_POST['url']; ?> this is standard tags instead <? echo $_POST['url'];?>

<? ?> is short tags, need short_open_tag enabled in php.ini

Upvotes: 1

Related Questions