chandan111
chandan111

Reputation: 251

HTML Forms in PHP

i am writing html form code with in php script

here it is

<?php
  $problem_code="STR";
  echo '<form name="submit-button" action="/codejudge/submit.php?id='.$problem_code.'">';
  echo '<button type="submit" >Submit</button>';
  echo "</form>";
?>

But after submitting url look like this localhost/codejudge/submit.php ? but it should be like this localhost/codejudge/submit.php?id=STR

Upvotes: 2

Views: 122

Answers (2)

Quentin
Quentin

Reputation: 944530

If a form is method="GET" (which is the default), as this one is, then submitting it will erase the existing query string in the action.

Store the data in a hidden input instead.

<?php
  $problem_code="STR";
?>
<form name="submit-button" action="/codejudge/submit.php">
  <input type="hidden" name="id" value="<?php echo htmlspecialchars($problem_code); ?>">
  <button type="submit">Submit</button>
</form>

Upvotes: 4

edtech
edtech

Reputation: 1754

You should specify a method of form submit.

$problem_code="STR";
echo '<form method=post name="submit-button" action="/codejudge/submit.php?id='.$problem_code.'">';
echo '<button type="submit" >Submit</button>';
echo "</form>";

Upvotes: 1

Related Questions