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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Something not right - session variables 1

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
My pages are working with PHP and MySql other than the following. Am working on localroot on pc.

The following extract shows the php code in the input box??
As it was a while ago, and on a remote site which worked, I cannot remember whether the session variable was first declared in other place, or if whats shown should work, or something amiss with my configuration of php?

<input name="QTY[1]" value="<?=$_SESSION['QTY'][1]?>" size="6" style="background-color: #FFFF00; font-weight:700" /><tr>
<?$_SESSION['PROD'][1]="DBC-6M"?>
<?$_SESSION['DURA'][1]="Digital Betacam 6 mins"?>

Many thanks
 
try the test a few times please.

I suspect that this indicates that the sessions are working fine, that php is working fine.

unfortunately that leaves the other errors down to pilot error! eg typos and similar errors.

are you perhaps using an html/php editor or other tool that might mangle the input? i.e. do you get the same behaviour if you use notepad or phpdesigner for your editing environment?
 
The site which has been on a hosted site was built with Frontpage 2003. I have used Frontpage 2003 to publish on localhost. I will try putting a couple of pages in my root without using FP to see what happens.
 
I have now put some pages directly into my documentroot.

The index page, which is a product selector loads okay.
On selection of a product, a product page opens okay. It has this in the browser:

I then enter numbers into a textbox, and the form accept button is pressed, which should then go to another page which looks at the session values of each textbox and clears those not having data in them. However I get a page not found error.

From here should goto but cannot find page

The form DBC.php has:
<form method="POST" action="../VDBC.php">

I have tried all combinations of changes (I think) on the above line but still does not find the page. Its in the root where index page is.

The same event problem is on another post to line in another form.

Many thanks for suggestions
 
is this a different issue?

why not hard code the action in the form?
Code:
<form method="post" action="[URL unfurl="true"]http://localhost/VDBC.php">[/URL]
 
Thankyou, that opened the next page which checks all the sessions variables for content, otherwise unsets them, when done it should go back to the menu. However it's unhappy after me trying to correct the following bit

header("\\ header("Location:newmenu.php");
header("Connection: close");
?>

Code at end of form. Location bit was something, can't remember, however the page creates havoc!! with errors.

I think I should have started this as a new thread, as stars owed are piling up. Regards
 
this line must point to a file in the same directory.
header("Location:newmenu.php");
if not then i'd suggest you hard code this url too.

header ("Location:
call exit() after a redirect. i'm not sure what the Connection: close would add to just ending the script.
 
I hard coded in the URL header("Location:index.htm");
sorry about the old name change, from the Frontpage site.

However I got lots of errors still.

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\wamp\ on line 35

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\wamp\ on line 35

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\wamp\ in C:\wamp\ on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\ in C:\wamp\ on line 2

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\ in C:\wamp\ on line 34

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\ in C:\wamp\ on line 35

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\ in C:\wamp\ on line 36

The page looks like this:

<?
session_start();


// DIGITAL BETACAM ARRAYS

// Get rid of existing arrays

if (isset($_SESSION['QTY'][1])) {unset ($_SESSION['QTY'][1]); }
elseif (isset($_SESSION['QTY'][2])) {unset ($_SESSION['QTY'][2]); }
elseif (isset($_SESSION['QTY'][3])) {unset ($_SESSION['QTY'][3]); }
elseif (isset($_SESSION['QTY'][4])) {unset ($_SESSION['QTY'][4]); }
elseif (isset($_SESSION['QTY'][5])) {unset ($_SESSION['QTY'][5]); }
elseif (isset($_SESSION['QTY'][6])) {unset ($_SESSION['QTY'][6]); }
elseif (isset($_SESSION['QTY'][7])) {unset ($_SESSION['QTY'][7]); }
elseif (isset($_SESSION['QTY'][8])) {unset ($_SESSION['QTY'][8]); }
elseif (isset($_SESSION['QTY'][9])) {unset ($_SESSION['QTY'][9]); }
else {/*do nothing;*/}


// Put data into arrays
// DIGITAL BETACAM

if ($_POST['QTY'][1]>0) $_SESSION['QTY'][1] = $_POST['QTY'][1];
if ($_POST['QTY'][2]>0) $_SESSION['QTY'][2] = $_POST['QTY'][2];
if ($_POST['QTY'][3]>0) $_SESSION['QTY'][3] = $_POST['QTY'][3];
if ($_POST['QTY'][4]>0) $_SESSION['QTY'][4] = $_POST['QTY'][4];
if ($_POST['QTY'][5]>0) $_SESSION['QTY'][5] = $_POST['QTY'][5];
if ($_POST['QTY'][6]>0) $_SESSION['QTY'][6] = $_POST['QTY'][6];
if ($_POST['QTY'][7]>0) $_SESSION['QTY'][7] = $_POST['QTY'][7];
if ($_POST['QTY'][8]>0) $_SESSION['QTY'][8] = $_POST['QTY'][8];
if ($_POST['QTY'][9]>0) $_SESSION['QTY'][9] = $_POST['QTY'][9];

header("Location:index.htm");
\\ header("Location:newmenu.php");
header("Connection: close");
?>


Probably get shot filling up the site, but it may help.
Best regards
 
Like a fool, I have just sussed out my rem slashes the wrong way round. Pages now open, but returning to product page DBC.php does not hold previuosly entered data. What a pain in the neck. I think I will forward the page to another one, in case the index page is losing it. I know it has bits of Frontpage left in it. I did all this somewhile ago, theres a lot to clean up, use arrays etc. But if I can solve this headache first I will be greatfull.
 
Nope, the session value gets lost, back to why. Sorry jpadie, you have worked hard on this, have a star, packing it in for tonight. Thanks again
 
what you're seeing is a race condition on the files that hold the session data. you would not get this if your site was not local. basically you are arriving at the new page before php has had a chance to save the text file containing the session data after leaving the old page.

there is a cure that *should* work.

add the following line after you have finished assigning the variables to the session:

Code:
session_write_close();
 
Many Thanks again. I tried adding session_write_close but nothing changed. I then completely bit by bit stripped my product input form of its tables, other inputs etc untill a bare minimum was left. Still cannot retrieve session value, unless something in my code is not getting noticed.

The two forms are now:

Form named index.php

<?
session_start();
?>

<form method="post" action="
<input name="QTY[1]" value="<?=$_SESSION['QTY'][1];session_write_close?>" /><tr>

<input type="submit" value="submit" style="font-weight: 700"></td>

<p>
&nbsp;</p>
</form>

----------------------------------

Form named ending.php

<?php
session_start();
$name=$_SESSION['QTY'][1];
echo $name
?>

Soon I will put my pc in the bin.

Many thanks
 
i'm a bit lost by your post above.

in the first file you are assigning the current value of $_SESSION['QTY'][1] to the form field's value. you are not changing the value of the array element.
the form is then displayed and the current value of the session element will be in the input field (by the way it is ia good idea to specify the type of the element in html)

when the user presses submit he goes to the next page and you then completely ignore the form and echo out the same variable that you have assigned to the form before in the previous page. again you are doing nothing to change that variable.

whereabouts are you actually setting $_SESSION['QTY'][1]?
 
You are correct, sorry, I was trying to eliminate the number of forms in testing, using original Frontpage pages that I was slowly removing bits from to see any cause. And you were right, $_SESSION['QTY'][1] was not getting any data in it in the first place.
Having done the tests with your earlier code, and my previous posting, I need to take things apart to see why its not working locally. I will start a new posting when I find more, as its grown too long, and only one star to issue. Many thanks, back soon.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top