1

I have the following html form in one of my php files:

<form action="reply.php?id=$id" method="post" class="form-horizontal" role="form">

When this form is submitted I want to pass the $id variable from this file into my reply file.

In my reply file I have used the following get method but all that is stored in the $queryid variable is $id instead of the int value that it should be.

$queryid = (int)$_GET['id'];

I realise it's probably something simple I am missing but I just can't seem to work it out.

2
  • 2
    You have to show more of your HTML, but I guess that you have to echo original $id inside HTML using php tags: <form action="reply.php?id=<?php echo $id; ?>" method="post" class="form-horizontal" role="form"> Commented Mar 30, 2016 at 23:36
  • That's all I was missing! Thank you. Don't know how I missed that Commented Mar 30, 2016 at 23:40

2 Answers 2

2

You need to echo the ID in php right, now you are literally assigning the Id to "$id"

Use this:

<form action="reply.php?id=<?php echo $id; ?>" method="post" class="form-horizontal" role="form">

But I would recommend just inserting the ID as a hidden input and sending it with the rest of the post data.

<input type="hidden" value="<?php echo $id; ?>" name="id"> </input>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I only had the method="post" missing, once I put that in, boom!
0

Try this:

<?php 
    $queryid = isset($_GET['id']) ? $_GET['id'] : '';
?>
<form action="reply.php?id=<?php echo htmlspecialchars($queryid); ?>" method="POST" class="form-horizontal" role="form">

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.