Virtual
Virtual

Reputation: 21

PHP code is displayed in my form field

Is this correct if I'm trying to get a date value inside an input box? When running the page, I get <?=$todate?> inside the box instead of the actual date.

$todate=$_REQUEST['todate'];

That is how I am requesting the $todate variable.

Upvotes: 0

Views: 98

Answers (3)

user1433439
user1433439

Reputation:

I guess you embedded PHP in an .html file. Copy your code into a .php file (e.g. test.php), start your webserver (e.g. apache in xampp) and call your script via URL in browser:

http://localhost/test.php?todate=12.02.1980

PHP-Code:

<?php 
    if(isset($_REQUEST['todate'])) 
        $todate = $_REQUEST['todate'];
    else
        $todate = null;
?>

HTML:

<form name="myForm">
    <input type="text" value="<?=$todate; ?>"> 
</form>

Upvotes: 0

zavg
zavg

Reputation: 11061

Set

short_open_tag = on

in php.ini and restart your web server.

Upvotes: 0

Ethan
Ethan

Reputation: 2784

Either turn on short tags in your php.ini file, or convert your code to <?php echo $var;?>... and make sure your page is being parsed as PHP

Upvotes: 2

Related Questions