tags:

views:

102

answers:

6

hi, i want to pass php variable value as a action to html form. i am trying as follows, but it is not working.

<?php
$url='test.php';
?>
<html>
<body>
<form name="upload" action="<?=$url?>" method="post" >
<input type="submit" value="submit">
</form>
</body>
</html>

All this code are in one php file.

+1  A: 

Try this

<form name="upload" action="<? echo $url ?>" method="post" >
nc3b
i have allready tried with this, but this also not working
MAS1
Or `<form name="upload" action"<?=$url;?>" method="post">`, without the single quotes wrapping the php snippet.
Jorge
If it's not working, try looking at the source output and paste that line
nc3b
Thanx for your post
MAS1
+3  A: 

Have you tried <?php echo $url ?> If it works, then short_open_tag in the php.ini is turned off. That means you will need to either turn it on or use the long open tag <?php throughout your code.

webbiedave
Thanx,I turn on short_open_tag. it's working now.
MAS1
+1  A: 

Remove your single quotes:

<form name="upload" action="<?=$url?>" method="post">
Jakob Kruse
tried without single quote, still not working
MAS1
Thanx for your post
MAS1
A: 

instead of this try

action="'<?=$url?>'"

action="<?php $url ?>"
Steve Robillard
tried with this also, still not working
MAS1
Thanx for your post
MAS1
A: 

Instead of only saying "it is not working", you should provide the generated HTML.

laurentb
+1  A: 

Sounds like you need to enable short_open_tag if your example doesn't work.

<?php
ini_set('short_open_tag', 'on');
$url='test.php';
?>
<html>
<body>
<form name="upload" action="<?=$url?>" method="post" >
<input type="submit" value="submit">
</form>
</body>
</html>

Alternately, write it like this:

<?php
$url='test.php';
?>
<html>
<body>
<form name="upload" action="<?php echo $url ?>" method="post" >
<input type="submit" value="submit">
</form>
</body>
</html>
rmarscher