Sahitya Sahitya - 5 months ago 14x
PHP Question

GET from another page and POST on the current page

I am creating a script and I came across a problem. I am having to use $_POST and $_GET on the same page, which I don't think makes sense.

I get the value for user id using the GET method from another page through a link and I have to input data from a form into the database in the current page.

CODE SNIPPET 1 : (GET METHOD on page page.php)

echo "<td align=center width=90px height=10px><strong><a href='sessions.php?id=".$userid."' style=text-decoration:none><font color='red' size='5pt'>$i</font></a></strong></td>";

CODE SNIPPET 2 : (POST METHOD on sessions.php going to same page sessions.php)


Can I get the userid from the url and the POST the values from the form in the same page?
If not, is there a way I can do this better?


You can use one hidden input field in your form in session.php and store $_GET['id'] in value attribute of that input field and it will be pass with your form submit to session.php <input type="hidden" value="<?php echo $_GET['id']">