Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session errors 3

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
Can someone be good enough to point out why I am getting the following error.

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/R2D2/public_html/Digi.php:7) in /home/data8251/public_html/Digi.php on line 7

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/R2D2/public_html/Digi.php:7) in /home/data8251/public_html/Digi.php on line 7

The page code is:

<!DOCTYPE html

PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"

<?php session_start(); // This connects to the existing session
session_register ("DB6"); // Create a session variable called name
$HTTP_SESSION_VARS ["DB6"] = $name; // Set name = form variable $name
?>



<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
<html xmlns=" xml:lang="en" lang="en">
<title>Submission Form</title>

</head>


<body>


<table class="Fatscope" width="84%" border="1">


<tr>
<td class="DescriptorCell" width="96%" bgcolor="#E7EFF7" colspan="4"><b>
<font face="Arial" size="5" color="#0000FF">Fuji D321 Digital Betacam</font></b></td>
</tr>


<tr>
<td class="DescriptorCell" width="34%" bgcolor="#E7EFF7"><b>
<font face="Arial" size="4">Product</font></b></td>
<td class="DescriptorCell" bgcolor="#E7EFF7" width="25%"><b>
<font face="Arial" size="4">Duration</font></b></td>
<td class="ContentCell" width="5%" bgcolor="#E7EFF7" align="center">
<b><font face="Arial" size="4">Qty</font></b></td>
<td class="ContentCell" width="32%" bgcolor="#E7EFF7">
&nbsp;</td>
</tr>


<tr>
<td class="DescriptorCell" width="34%" bgcolor="#FFFFFF" height="26">
<font face="Arial"><b>DBC-6</b></font></td>
<td class="DescriptorCell" bgcolor="#FFFFFF" height="26" width="25%">
<font face="Arial"><b>6mins</b></font></td>
<td class="ContentCell" width="5%" bgcolor="#FFFFFF" height="26">
<p align="center"><font size="3">
<input name="DB6" size="5" tabindex="1" style="background-color: #FFFF00"></font>

<td class="ContentCell" width="32%" bgcolor="#FFFFFF" rowspan="3" align="center">
&nbsp;</td>
</tr>


<tr>
<td class="DescriptorCell" width="34%" bgcolor="#FFFFFF">
&nbsp;</td>
<td class="DescriptorCell" bgcolor="#FFFFFF" width="25%">
&nbsp;</td>
<td class="ContentCell" width="5%" bgcolor="#FFFFFF">
<p align="center">
&nbsp;</td>
</tr>


<tr>
<td class="DescriptorCell" width="34%" bgcolor="#FFFFFF">
&nbsp;</td>
<td class="DescriptorCell" bgcolor="#FFFFFF" width="25%">
&nbsp;</td>
<td class="ContentCell" width="5%" bgcolor="#FFFFFF">
<p align="center">
&nbsp;</td>
</tr>



</table>


</body>
</html>


If I can follow the structure of this then I will use it for all the other pages I am now trying to hold tegether with php. Many thanks
 
Dimensions a variable"? "control"? The first step toward thinking in PHP is to quit using all the ASP jargon.

session_start();
Starts the session-handling mechanism.
$_SESSION ['DB6V'];
Actually, this line is redundant and should be removed.
$_SESSION ['DB6V'] = $DB6;
This line creates and element in the array $_SESSION with the index DB6B and copies the value from the variable $DBV6 into it.

Have you verified that the value you expect is in $DB6? Or are you just assuming. If this value is supposed to come from data from a form element named "DB6", then with a default PHP installation $DB6 will not exist. One of $_POST['DB6'] or $_GET['DB6'] will, depending on whether your HTML form uses the POST- or GET-method, respectively.

The reason why the variable $DB6 will not exist in a default PHP installation is explained in the PHP online manual: Chapter 29: Using Register Globals

I also cover this in my FAQ titled "Debugging PHP": faq434-2999

The following works on my installation:

test_session1.html:
Code:
<html><body>
<form method="POST" action="test_session1.php">
<input type="text" name="foo"><br>
<input type="submit">
</form>
</body></html>

test_session1.php:
Code:
<?php
session_start();

$_SESSION['foo'] = $_POST['foo'];

print '<html><body>
<a href="test_session2.php">click here</a>
</body></html>';
?>

test_session2.php:
Code:
<?php
session_start();

print '<html><body>The value of foo is: ' . $_SESSION['foo'] . '</body></html>';
?>

If I point my browser to test_session1.html, I get a form with one field and a submit. If I fill in hello in that field and submit, I get a link. If I click on that link, I get:

The value of foo is: hello


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Many thanks sleipnir214, I have tried that at my end and it works. What I now need to try is this. I need to go from a menu page to a version of your test_session1.html page. From there go to a version of your test_session1.php page, but not stop there, but to move back to the menu page. There the user will select another version of your test_session1.html page etc, etc. Then at the end, obviuosly having added all the version additions of $_SESSION['foo'] = $_POST['foo']; etc along the line, will I then still be able to go to test_session2.php to get all the results out. Does it look feaseable. If so I'm on my way at last. Thanyou again for all the time.
 
There is no rule that says each part of a web application must be separate files. I've been using separate script files in my examples here because I needed to simplify the scripts as much as possible for pedagogical reasons.

Try this script on for size. It doesn't matter what you name it.

Code:
<?php
session_start();

if (!isset($_SESSION['foo']))
{
	$_SESSION['foo'] = array();
}

if (isset($_POST['foo']))
{
	if (strlen($_POST['foo']) > 0)
	{
		$_SESSION['foo'][] = $_POST['foo'];
	}
}

if (isset ($_POST['todelete']))
{
	foreach ($_POST['todelete'] as $key_to_delete)
	{
		unset ($_SESSION['foo'][$key_to_delete]);
	}
}


print '<html><body><form method="POST" action="' . $_SERVER['PHP_SELF'] . '">';

if (count($_SESSION['foo']) > 0)
{
	print 'The session variable "foo" currently contains:<br>
<table>
	<tr>
		<td>
			DEL?
		<td>
			&nbsp;';

	foreach ($_SESSION['foo'] as $key => $value)
	{
		print '
	<tr>
		<td>
			<input type="checkbox" name="todelete[]" value="' . $key . '">
		<td>
			' . $value;
	}

	print '</table>';
}
else
{
	print 'The session variable "foo" is empty.<br>';
}

print '<hr>
Add a value: <input type="text" name="foo"><br>
<input type="submit">
</form>
</body></html>';

?>


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Its good when you know what your doing. Very impressive, informative. I am beginning to see what you mean regarding the scope of PHP. I am at last getting towards what I was looking for with your help. I have adopted you method of using "Post", and it seems to be making sense at last. I am able to go from a menu, to a page with input boxes, and return to the menu again. When I go to your 3rd page test_session2.php, its there.
Very greatful to you. And a thanks to others comming in.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top