Jump to content

[SOLVED] Problem on passing on and changing session variables


peddel

Recommended Posts

Ok im gonna try to explain it as detailed as i can,

cuz my project has over 50 pages of code with 800- 1000 lines each  :o

 

Ive got a form called PR1.php

Inside this form the user gives in tons of values he measured inside the factory.

When he filled in all his fields needed, he presses the submit button.

What happens then is the following :

- a javascript checks if all the fields are filled in

- when a true has been returned from the script, page tussenstapPR1.php is loaded.

 

Inside form called tussenstapPR1.php

Things that happen here in this order

- i get all the values of the submitted fields by using for example : $vf1V = $_POST['vf1V'];

- at the same time i ask all the values to be putted inside a session variable by using for example : $_SESSION['vf1V'] = $vf1V;

The form continues and now checks trough php and mysql if the entered values in the previous forms are between a top and a bottom value.

Code use for this is for example :

$sql = "SELECT * FROM tag_grenzen_constanten WHERE tag='OO-PI-001'";
$result = @mysql_query($sql); if(!$result){print("Query mislukt [".mysql_error()."]"."<br />");};
$row = mysql_fetch_array($result);
if(!((int)$row['bovengrensOperator'] > (int)$vf1V) || !((int)$row['ondergrensOperator'] < (int)$vf1V)){
print("<tr><td class='hoofdtitel' align='center'>");
print("De waarde die je ingaf voor OO-PI-001 = ".$vf1V." is onmogelijk.");
print("</td></tr><tr><td class='kortvak' align='center'>");
print("Gelieve de juiste waarde in te geven en nogmaals te controleren. <input type='text' name='vf1V' size='15' />");
print("</td></tr>");
}

U can see every time the value is wrong and not between the top and bottom value, 2 things are done :

- a message that value is wrong

- a new textfield to enter the value

At the end of this form there is a submit button. By clicking it we go to ingediend1.php

 

Inside form called ingediend1.php

we first include 2 files named test.php and verwerking1.php

<?php
	include("test.php");
	include("verwerking1.php");
?>

We enter the test.php and find this code :

session_start();

foreach ($_POST as $fld => $val) {
	unset($_SESSION['$fld']);
	$_SESSION['$fld'] = $val;
}

This code runs trough all the fields of the wrong values in the tussenstapPR1.php

It takes the value

- drops the existing session variable added to that fieldname (which has been made inside tussenstapPR1 at the beginning

- add the new value to a new session variable with the name of the field

 

Now i go to verwerking1.php

- here all the session values are taken and put inside a mysql database.

 

MY PROBLEM NOW  ;D i know alot to read  :P

In my database the value of the changed wrong items is still the wrong value and not the thing i changed it into.

So i guess i got a problem with the session variables ...

Anyone sees why?

Link to comment
Share on other sites

how are they wrong values?

please post an example! :P

 

well imagine i first emitted 10 for the variable $vf1V

then i do $_SESSION['vf1V'] = $vf1V

 

now immagine the top value = 8 and bottom value = 2

U can see its not between the borders

 

so i ask for new value and enter like 6

 

but when submitted and all configured,

the database still got 10 inside and not the 6 at that position :P

so somewhere my session variable hasnt been changed, tough i did it i suppose

 

Link to comment
Share on other sites

You don't see your problem? :P

 

Look:

 

<?php
session_start();

$me = "marcus";

$_SESSION['$me'] = "fail session";
$_SESSION[$me] = "correct session";

print_r($_SESSION);
?>

 

Results:

Array ( [$me] => fail session [marcus] => correct session ) 

 

Don't use the single quotes when you're defining and unsetting the sessions.

Link to comment
Share on other sites

Man thank u for the help  ;)

Its just when ur making that much code, ive been programming for 3 weeks now ...  :o

It sometimes is hard to find those easy mistakes.

But indeed i need the name written in the variable and not the $fld as name :D

 

This helped me out ! thx for ur help and time

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.