Page 1 of 1

Please help, code not working when it should *SOLVED*

Posted: Tue Nov 16, 2010 9:51 am
by zaster79
PLEASE, PLEASE PLEASE HELP ME. This is driving me insane.

I have a form (form.php) that is submitted to itself. All it has to do is assign the text from the textarea to a session variable, simple yes?

It doesn't work, the session variable always remains empty, in fact the (if (isset)) check returns false, when it clearly isn't, I can see the data in the get request URL. However if I use...

Code: Select all

echo $_GET['report'];
It displays the contents of the textarea

This is driving me crazy, can someone please take a look. My code is below.

Code: Select all

<?php
session_start();
if (isset($_GET['report'])) {
$_SESSION['session_report'] = $_GET['report'];
//do some other stuff
}
?>

<html>
<form action = 'form.php' method = GET>
		Please submit your report below<br />
		<textarea name='report'></textarea><br />
		<input type='submit' value = 'Submit' />	
</form>
</html>
Also, it doesn't matter if I use a session variable or a erm... normal? variable. I just can't get the contents of the textarea into a variable. Server issue?

Re: Please help, code not working when it should (I think)

Posted: Tue Nov 16, 2010 10:57 am
by s992
I copy-pasted your code and it works fine for me... what do you get when you try to echo $_SESSION['session_report']?

Re: Please help, code not working when it should (I think)

Posted: Tue Nov 16, 2010 4:01 pm
by thinsoldier
not tested

Code: Select all

<?php
session_start();

// var_dump($_GET);
// var_dump($_SESSION);

if (isset($_GET['report'])) 
{
	$_SESSION['session_report'] = $_GET['report'];
}

var_dump($_SESSION);

?><html>
<head>
<body>
	<form method="get" action="form.php">
		<input type="text" name="report">
		<input type="submit">
	</form>
</body>
</html>

Re: Please help, code not working when it should (I think)

Posted: Wed Nov 17, 2010 3:51 am
by zaster79
SOLVED

OMG!

Thanks for the replys, it always helps.

Don't know WTF was gong on but I turns out that my text editor (notepad++) had started saving the entire contents of the file to a single line despite displaying multi line in the editor as you would expect. I know in theory this should work, but I think certain commented lines were causing problems in this format.

I opened the file in notepad and added the carradge returns again, uploaded the file and it worked just fine.

Problem is, I have no idea when this started, I'll have to look at a lot of my code again.

So, not a code problem afterall. My sanity is saved.

Thanks again for the help.