[SOLVED] PHP Session Variables in a form

This is a discussion on "[SOLVED] PHP Session Variables in a form" within the PHP Forum section. This forum, and the thread "[SOLVED] PHP Session Variables in a form are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 12th, 2007, 17:33
New Member
Join Date: Feb 2007
Location: London
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] PHP Session Variables in a form

Help, please, I'm going in circles with this.

I get the 'Warning: Cannot modify header information ' message at the top of the page, and onSubmit nothing happens.

Any ideas?

Thanks for any help!
PHP: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"

"[url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd[/url]">
<html xmlns = "[url]http://www.w3.org/1999/xhtml[/url]">
<head>
<?php
ob_start
(); 
$_SESSION['confint'] = - - $_POST['ConfidenceInterval'];
$_SESSION['mood1'] = - - $_POST['mood-slider1'];
$_SESSION['mood2'] = - - $_POST['mood-slider2'];
$_SESSION['mood3'] = - - $_POST['mood-slider3'];
$_SESSION['mood4'] = - - $_POST['mood-slider4'];
header("Location:http://localhost/Dissertation/listen.php");
ob_end_flush();
?>
<title>Selection Page</title>
<script src="javascripts/prototype.js" type="text/javascript"></script>
<script src="javascripts/slider.js" type="text/javascript"></script>
<link rel="stylesheet" type = "text/css" href="dissertation.css"></link>
</head>
<body>
<p>
<p align="center">
 
<form name="sliderform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="slider-form">
<table border="0" cellpadding="1" width="100%" height="384">
 
<tr>
<td> <p align="justify"><font color="#000000">
<b>
<span><font face="Verdana">Selection</font></span>
</b>
</p>
</td>
</tr>
<tr>
<td valign="top">
 
<p><b>Confidence Interval</b></p>
<p>
<label>5%</label><input type="radio" checked name="ConfidenceInterval" value="0.05" >
<label>15%</label><input type="radio" name="ConfidenceInterval" value="0.15">
<label>25%</label><input type="radio" name="ConfidenceInterval" value="0.25" tabindex="3">
</p>
 
<p><b>Instructions to the User</b></p>
<ul>
<li>Select the confidence interval you wish to use</li>
<li>Set your mood levels using either the sliders or <br/>
the boxes at the end of each slider where you <br/>
can set the number</li>
<li>Click on the Submit button to retrieve tracks that <br/>
match the criteria</li>
</ul>
</td>
 
<td> 
<h2>Happy Slider</h2> 
<div id="track1" style="width:300px; background-color:#aaa; height:2px;">
<div id="mood1" style="width:10px; height:3px; background-color:#f00; cursor:move;"></div>
</div>
<p id="debug1">&nbsp;</p>
 
<h2>Mellow Slider</h2> 
<div id="track2" style="width:300px; background-color:#aaa; height:5px;">
<div id="mood2" style="width:10px; height:5px; background-color:#f00; cursor:move;"></div>
</div>
<p id="debug2">&nbsp;</p>
 
<h2>Sad Slider</h2> 
<div id="track3" style="width:300px; background-color:#aaa; height:10px;">
<div id="mood3" style="width:10px; height:5px; background-color:#f00; cursor:move;"></div>
</div>
<p id="debug3">&nbsp;</p>
 
<h2>Brooding Slider</h2> 
<div id="track4" style="width:300px; background-color:#aaa; height:10px;">
<div id="mood4" style="width:10px; height:5px; background-color:#f00; cursor:move;"></div>
</div>
<p id="debug4">&nbsp;</p>
</td>
</tr>
 
</table>
<input type="hidden" id="mood-slider1" name="mood-slider1" value="0" />
<input type="hidden" id="mood-slider2" name="mood-slider2" value="0" />
<input type="hidden" id="mood-slider3" name="mood-slider3" value="0" />
<input type="hidden" id="mood-slider4" name="mood-slider4" value="0" />
<input type="submit" name="submit" value="Retrieve Tracks" />
</form>
<script type="text/javascript" language="javascript">
// <![CDATA[
 
// horizontal slider1 control
new Control.Slider('mood1', 'track1', {
onSlide: function(v) { $('debug1').innerHTML = "<font size=-1>slide: " + v; $('mood-slider1').value = v +"<font/>"; },
onChange: function(v) { $('debug1').innerHTML = "<font size=-1>value: " + v; $('mood-slider1').value = v +"<font/>"; }
});
 
// horizontal slider2 control
new Control.Slider('mood2', 'track2', {
onSlide: function(v) { $('debug2').innerHTML = "<font size=-1>slide: " + v; $('mood-slider2').value = v +"<font/>"; },
onChange: function(v) { $('debug2').innerHTML = "<font size=-1>value: " + v; $('mood-slider2').value = v +"<font/>"; }
});
 
// horizontal slider3 control
new Control.Slider('mood3', 'track3', {
onSlide: function(v) { $('debug3').innerHTML = "<font size=-1>slide: " + v; $('mood-slider3').value = v +"<font/>"; },
onChange: function(v) { $('debug3').innerHTML = "<font size=-1>value: " + v; $('mood-slider3').value = v +"<font/>"; }
});
 
// horizontal slider4 control
new Control.Slider('mood4', 'track4', {
onSlide: function(v) { $('debug4').innerHTML = "<font size=-1>slide: " + v; $('mood-slider4').value = v +"<font/>"; },
onChange: function(v) { $('debug4').innerHTML = "<font size=-1>value: " + v; $('mood-slider4').value = v +"<font/>"; }
});
// ]]>
</script>
</body>
</html>

Last edited by Rakuli; Oct 12th, 2007 at 10:05. Reason: Just popping in some [php][/php] tags to aid readability
Reply With Quote

  #2 (permalink)  
Old Feb 12th, 2007, 20:02
New Member
Join Date: Feb 2007
Location: London
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP Session Variables in a form

Thanks to anyone who read this.

I don't nee the help now as I have found a way around it.
Reply With Quote
  #3 (permalink)  
Old May 7th, 2007, 19:24
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP Session Variables in a form

Just saw this, sorry. You need to put all the session info first, before you send anything to be displayed in the browser. AFAIK it needs to go even before the DOCTYPE declaration.
PHP: Select all

 <?php
ob_start
(); 
$_SESSION['confint'] = - - $_POST['ConfidenceInterval'];
$_SESSION['mood1'] = - - $_POST['mood-slider1'];
$_SESSION['mood2'] = - - $_POST['mood-slider2'];
$_SESSION['mood3'] = - - $_POST['mood-slider3'];
$_SESSION['mood4'] = - - $_POST['mood-slider4'];
header("Location:http://localhost/Dissertation/listen.php");
ob_end_flush();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
 <html xmlns = "http://www.w3.org/1999/xhtml">
 <head>
If you want to use the output buffer to avoid this, use it for the html.

Last edited by masonbarge; May 7th, 2007 at 19:27.
Reply With Quote
  #4 (permalink)  
Old May 7th, 2007, 19:32
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 233
Thanks: 4
Thanked 0 Times in 0 Posts
Re: PHP Session Variables in a form

ob_start() needs to go before the DOCTYPE selector, but ob_end_flush() can go anywhere. Personally, I typically place it just before my opening <form> tag. (If you're going to display a form, you're truly ready to output content to the page, right?) This works well for me.
Reply With Quote
  #5 (permalink)  
Old Oct 12th, 2007, 09:56
New Member
Join Date: Feb 2007
Location: London
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP Session Variables in a form

I've not been logged in for a while. Happily I finished my dissertation and passed with flying colours. Thansk for all your help on this I really appreciate it. I know that when I have my next web project, I shall be back to ask more questions. I'll also check in from time to time to see if I can help some other poor stuck soul.
Reply With Quote
Reply

Tags
form, header, php, session

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] php re-writing variables in config from form Emzi PHP Forum 2 Jan 22nd, 2008 07:58
Session variables ideleon PHP Forum 2 Feb 7th, 2006 08:04
Session Variables.... courtjester Classic ASP 11 Jul 6th, 2004 00:04
Session Variables ekendricks Classic ASP 4 Dec 19th, 2003 06:33
Session Variables ekendricks Classic ASP 7 Aug 26th, 2003 10:42


All times are GMT. The time now is 11:20.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43