Why are the values of my form getting lost in php when sending them to an includes folder?

53 Views Asked by At

I am creating a messaging system in my website. I have a GET variable that I retrieve from the URL which indicates which user the inputted message should be sent to. I store this variable (messagesTo = $_GET['id']) in a form (with the message body and the logged-in user's id) and once the message is clicked, theoretically the included page should be called and the message should be stored in a DB based on the form's data.

URL w/ user's id inside of it

Form page (directMessages.php)

Instead, it says I get an error with the $_GET['id']. I have an error check and the message in the URL says that there is no value for $_GET['id']. No message is being sent to the database.

directMessages Included page (directMessages.inc.php)

Functions page for direct (dmFunctions.inc.php)

1

There are 1 best solutions below

0
On

You're not outputting the hidden values in your form (directMessages.php), ie:

<input name="messagesTo" type="hidden" value="<?php $_GET['id'] ?>">

should be

<input name="messagesTo" type="hidden" value="<?php echo $_GET['id']; ?>">

Basically you need to echo the value for it to be present in the HTML.