Click to See Complete Forum and Search --> : Sessions


Redhead
03-03-2004, 10:07 AM
Hi There

I need help with my sessions. I'm trying to carry over values in a form when the use selects the next button.

I keep getting these errors
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/special1-2-1.php:7) in /home/special1-2-1.php on line 7

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/special1-2-1.php:7) in /home/special1-2-1.php on line 7

Here is my php code:

<?php session_start();
if ( isset($_POST["item"]) || isset($_POST["price"]) || isset($_POST["FRM_3"]) )
{
$_SESSION["page1"] = $_POST["item"];
$_SESSION["page1"] = $_POST["price"];
$_SESSION["page1"] = $_POST["FRM_3"];
header("location: ./special1-2-2.php");
}
?>

Does anyone have any iedas?:confused:

Jona
03-03-2004, 10:14 AM
You'll have to put this code at the very beginning of the PHP document, you can't use any HTML before it, at all.

[J]ona

Redhead
03-03-2004, 10:18 AM
It is!

The above code is just after the </head> and before the <body> tages

i have javascript after the php code as well

so i have

</head>
<?php
the above php code
?>
<SCRIPT LANGUAGE="JavaScript">
all my javascript stuff
</script>
<body>
all my html stuff
</body>
</html>


:confused:

Jona
03-03-2004, 10:20 AM
It should be before anything. Before the <HTML> tag, and even before your DTD. It should first have the PHP code, then have the HTML.

[J]ona

Redhead
03-03-2004, 10:28 AM
WOW, i guess i'm a big dolt today i must be having some major brain farts :D

Thanks So much!!!! :)

Jona
03-03-2004, 10:30 AM
Happy to help. :)

[J]ona

Redhead
03-03-2004, 11:02 AM
I Need help again with a session..

One of the valuse i'm trying to carry over is a list box..
The value of the box is estableshed by the user

i need to know how to carry that over can you still help me if i give you a link to what i'm trying to do.

Jona
03-03-2004, 11:26 AM
Yes, a link would be nice.

[J]ona

Redhead
03-03-2004, 11:32 AM
this will just give you an idea of what i'm trying to do

http://www.cityscout.ca/test/special1-2-1.php


:D

Jona
03-03-2004, 11:38 AM
It looks like the code works... I don't see what the problem is. :confused:
Maybe you should try using $_SESSION["page1_1"], $_SESSION["page1_2"], and so on, instead of using three $_SESION["page1"] variables?

[J]ona

Redhead
03-03-2004, 11:46 AM
INSERT INTO ordertemp (item,price,topings,extras,drinks) VALUES ('Single 16 Inch Extra Large W/Pop','13.99','','','')


<?php session_start();
if ( isset($_POST["item"]) || isset($_POST["price"]) || isset($_POST["topings"]) )
{
$_SESSION["item"] = $_POST["item"];
$_SESSION["price"] = $_POST["price"];
$_SESSION["topings"] = $_POST["topings"];
header("location: ./special1-2-2.php");
}
?>


you can see it's grabing item, and price but not topings..

topings is a list box, that the user can select many items

that's where i'm having the problems it not getting the list box items

Redhead
03-03-2004, 11:48 AM
I have attached a txt file of the code i'm using for the first page you see..

Jona
03-03-2004, 11:48 AM
You mean a multiple-select box? In that case, you'd have to name the box name[] but change "name" to whatever you want to name it. Then in PHP, loop through its values. That's the only way to do it.

[J]ona

Redhead
03-03-2004, 11:54 AM
Ok that makes since

right know the page i have attached above is a copy of the one page..

You mean a multiple-select box?

You mean a multiple-select box?
Yes

In that case, you'd have to name the box name[] but change "name" to whatever you want to name it.

Not sure what you mean

Then in PHP, loop through its values. That's the only way to do it.
How???

:confused:

Redhead
03-03-2004, 11:55 AM
If you go to the link above you will see you can add as many items as you want to the left list box.. That's the box i want to carry over

Jona
03-03-2004, 11:57 AM
An example can be found at http://cmm.sonoracabinets.com/testing/selAry.php


<?PHP
if(!isset($_GET["node"]) || $_GET["node"] != "process" && !isset($_POST["submit"])){
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head><title>Testing with Select Boxes and Arrays</title>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<form action="selAry.php?node=process" method="POST"><div>
<select size="4" name="selObj[]" multiple="multiple">
<option value="A">One</option>
<option value="B">Two</option>
<option value="C">Three</option>
<option value="D">Four</option>
</select><br>
<input type="submit" name="submit">
</div></form>
</body></html>
<?} else {?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head><title>Testing with Select Boxes and Arrays</title>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<p><?
$v = "";
foreach($_POST['selObj'] as $value) {
$v .= $value;

for ($i=1; $i<5; $i++) {
echo $i.". (";
echo $value.") ";
$pos = split($value, $i-1);
if($pos == $i){echo "No<br>";}
else{echo "Yes<br>";}
}
};
?></p>
</body></html>
<?}?>


[J]ona

Redhead
03-03-2004, 12:00 PM
If i select submit querry i get this error

Warning: Invalid argument supplied for foreach() in /home/justin/public_html/cmm/testing/selAry.php on line 29

Just wanted to let you know

Jona
03-03-2004, 12:01 PM
You'll need to select one or more options. :rolleyes:

[J]ona

Redhead
03-03-2004, 12:08 PM
what do you mean by that?

Jona
03-03-2004, 12:09 PM
It's a multiple select box. Click One, then hold shift and click Three. It will select the first three options. Then click Submit Query. ;)

[J]ona

Redhead
03-04-2004, 01:20 PM
Hi There

I have been working with the above example and have had no luck..

I'm still confused on how to carry the values of the third list box over to latter (at end be instered into a database)

Jona
03-04-2004, 07:44 PM
The name should have [] after it, so that PHP can treat its values as an array.

[J]ona

Redhead
03-04-2004, 08:30 PM
But adding [] will that not effect my javascript code?

Jona
03-04-2004, 08:31 PM
Originally posted by Redhead
But adding [] will that not effect my javascript code?

Ah! You have a point. I didn't think about that... As far as I know, there's no other way to do it. Sorry. :(

[J]ona

Redhead
03-04-2004, 08:51 PM
Shoot! That's what i was afrid of.. Not good news for me, oh well.. Just have to think of something else..

I make up stuff for me to try and do so i can learn. Mabie i should sleep on it and come up with another idea..

THANK YOU SO MUCH!!! :)

You have been a great help :)

Jona
03-04-2004, 09:16 PM
I'm only sorry I couldn't help more!

[J]ona

Redhead
03-05-2004, 07:03 AM
NP Thats Ok, I'm happy to get as far as I Did that's for sure :)