Hi, Everyone, I am trying to add a php variable to my form input action.
When I click the button to submit the form, the php var is not being added to the action url.

I have tried using ".." / '..' to try to add the php var to the form action

<form role="form" action="http://website.com/dir/page.php?bptspt=<? echo $order; ?>" method="post">

Any help would be appreciated, thanks in advance.

Dani AI

Generated

As suggested, first confirm the PHP variable actually has a value before the form is emitted. As hinted, many servers do not parse short tags (<? ... ?>), so the browser can end up seeing the literal PHP instead of the expanded value. Check the page source: if you see PHP code in the HTML, PHP didn’t run that snippet.

Safer fixes:

  • Build the action URL on the server and escape it for both URL and HTML contexts. Example pattern:
<?php
$action = 'https://website.com/dir/page.php?bptspt=' . urlencode($order);
?>
<form role="form" action="<?php echo htmlspecialchars($action, ENT_QUOTES, 'UTF-8'); ?>" method="post">
  • Prefer sending the value as POST data (hidden input) rather than embedding it in the query string. That avoids URL-encoding problems and keeps the form action simple:
<form role="form" action="https://website.com/dir/page.php" method="post">
  <input type="hidden" name="bptspt" value="<?php echo htmlspecialchars($order, ENT_QUOTES, 'UTF-8'); ?>">
  <!-- other inputs -->
</form>

Quick troubleshooting checklist

  • View page source to see whether PHP output appears or raw PHP code is present.
  • echo/var_dump($order) (or error_log) before the form to confirm it’s defined and non-empty.
  • Ensure the variable is set before the template runs (and in the same scope).
  • If the value comes from session, confirm session_start() was called.
  • If short tags are required, avoid relying on them; use <?php echo ... ?> or enable short_open_tag in php.ini (but enabling system-wide short tags is not recommended).

Tieback: follow ’s echo test and ’s short-tag check first — those two quick checks will usually reveal whether the problem is a missing value or a parsing issue.

Recommended Answers

All 2 Replies

Have you tried to echo the variable to make sure there is a resulting value before the form?

E.G. <p><? echo $order; ?></p><form role="form"...

do you have short tags enabled

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.