Jump to content

Recommended Posts

I have a problem with sessions.

I have two pages.

 

One is poruc.php and the second one is pocesor.php

in poruc.php i have a table with products listed from the database and in the cell of the each product i have the id of it and a text field for quantity and submit button

 

the form action is second page procesor.php

at that page i take the variable of the ID (so i can now which is the product) and the quantity and i store that in the session and then reload the poruc.php

 

but when i reload the poruc.php in the forms textfield for that product (id) i still get a zero and not a quantity i entered

 

here is the procesor.php page

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

<?php

session_start();

$idi=$_GET['idi'];

$izbroj=$_GET['izbroj'];

 

$_SESSION[$idi]=$izbroj;

header ("Location: poruc.php");

 

?>

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

 

 

 

Code:

 

begining of the poruc.php

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

<?php

include ("putanja..../sifre.inc");

session_start();

$gdesi = curPageURL();

?>

 

....

 

rest of the poruc.php Code:

 

<table class="price" border=0 cellpadding=0 cellspacing=0>

<tr>  <td width="7"><IMG SRC="img/kutija-11.gif"></td><td class="rowm">Slika</td><td class="rowm">Šifra</td><td class="rowm">Naziv</td><td class="rowm">Kategorija</td><td class="rowm">Opis</td><td width="7"><IMG SRC="img/kutija-12.gif"></td></tr>

 

<?php

 

    $db = mysql_connect($server, $proiz,$proizpass);

    mysql_select_db($baza,$db);

    mysql_query("SET NAMES utf8");

    mysql_query("SET CHARACTER SET utf8");

    mysql_query("SET COLLATION_CONNECTION='utf8_general_ci'");

$query="SELECT * FROM proizvodi WHERE kategorija = $vrsta";

$result=mysql_query($query);

 

$num=mysql_numrows($result);

 

mysql_close();

 

$i=0;

while ($i < $num) {

 

$id=mysql_result($result,$i,"id");

$slika=mysql_result($result,$i,"Slika");

$sifra=mysql_result($result,$i,"Sifra");

$naziv=mysql_result($result,$i,"Naziv");

$kategorija=mysql_result($result,$i,"Kategorija");

 

switch ($kategorija) {

// here is the list of categories not important for this part

    case "1": $kategorija = "kategorijeeee"; break;

}

 

 

$opis=mysql_result($result,$i,"Opis");

if(isset($_SESSION[$id]))

//$kolicina is a quantity

$kolicina=$_SESSION[$id];

else

$kolicina=0;

echo "<tr class=\"row1\">

          <td width=\"7\" background=\"img/kutija-vertikalno1.gif\"></td><td class=\"naziv\"><A rel=\"ibox\" href=\"img/proizvodi/$slika\"><IMG SRC=\"img/proizvodi/$slika\" border=0 width=\"105\" height=\"105\"></a></td><td class=\"naziv\">$sifra</td><td class=\"naziv\">$naziv</td><td class=\"naziv\">$kategorija</td><td class=\"naziv\">$opis</td><td class=\"naziv\"><FORM action=\"procesor.php\" method=\"GET\"><input type=\"text\" name=\"izbroj\" id=\"izbroj\" size=\"2\" value=".$kolicina."><input TYPE=\"hidden\" VALUE=$id NAME=\"idi\"><input type=\"SUBMIT\" value=\"DODAJ\" /></FORM></td><td width=\"7\" background=\"img/kutija-vertikalno2.gif\"></td>

              </tr>

      <tr><td width=\"7\" height=\"10\"><IMG SRC=\"img/kutija-levo.gif\"></td><td background=\"img/kutija-sredina.gif\"></td><td background=\"img/kutija-sredina.gif\"></td><td background=\"img/kutija-sredina.gif\"></td><td background=\"img/kutija-sredina.gif\"></td><td background=\"img/kutija-sredina.gif\"></td><td width=\"7\" height=\"10\"><IMG SRC=\"img/kutija-desno.gif\"></td></tr>

";

$i++;

}

?>

   

</table>           

 

 

any help

Link to comment
https://forums.phpfreaks.com/topic/190522-session-problem/
Share on other sites

it is not that

 

in the form i have a hidden field which set the value of $id to the idi and i get that value in the pocesor page and have $idi variable (which is the same as the $id) so i store that

 

and for the session variables i have placed the $idi variable and not the 'sometext' so in my logic when i have product id = 30 and quantity 100 he will store $_SESSION[$idi]=$izbroj; and that is $_SESSION[30]=100; am i right ?

 

it work ok at procesor.php page when i enter echo $_SESSION[30] i get value 100 ... but i don't know why then at the poruc.php in the cell where the id is 30 why doesn't he loads session value 100 and prints it out in the textfild kolicina/quantity

 

 

Link to comment
https://forums.phpfreaks.com/topic/190522-session-problem/#findComment-1004945
Share on other sites

 

yes i have this is the part of the code that loads just before printing out the cell of the table

 

if(isset($_SESSION[$id]))

//$kolicina is a quantity

$kolicina=$_SESSION[$id];

else

$kolicina=0;

 

it is in my first post too

 

it checks if the session for that id (example 30) is set then $kolicina (which is printed out in the cell form textfield) is equal to that value from session if not set it to 0 (this i am doing so the products id that are not set in the session have the value of 0 - not store all them in session)

 

 

Link to comment
https://forums.phpfreaks.com/topic/190522-session-problem/#findComment-1004948
Share on other sites

 

anyone ?

 

so the general problem is to transfer a variable from a form to another page and on that another page to store that variable value in the session and go back to first page and in that form field to be written new value

 

i have an variable $id i don't know it because it is inside the loop and read it from the db and there is a $quantity (kolicina) for that id so

 

i want the value of the variable $id (for example 30) and the variable $quantity (100) to be stored in the session and next thing when the original page loads that inside that table when the cell for that id comes true it prints a quantity of 100 and not 0

 

Link to comment
https://forums.phpfreaks.com/topic/190522-session-problem/#findComment-1005367
Share on other sites

okay how to set the condition to check if the value of one variable is set to the session

 

i have and $id which is 30 for example so i want to check if $_SESSION['30'] is set ?

it is in the loop so i must use variable $id and not 30 because it reads all the products from the db and each product have a different unique id

 

because i want to have $_SESSION['30']=100; which means for product 30 quantity is 100

so in the loop when i read all the products and display them in a cells i want to promty for the none set products quantity 0 and for the one that is set like the 30 one to display 100 and not 0

 

can you helo

Link to comment
https://forums.phpfreaks.com/topic/190522-session-problem/#findComment-1005380
Share on other sites

Why not check what is in the $_SESSION array so that you know if poruc.php is receiving the data? Add the following lines of code intermediately after the session_start() statement -

echo "<pre>";
print_r($_SESSION);
echo "</pre>";

 

And if that shows an empty array, add the following two lines of code immediately after the first opening <?php tag so that php will display all the errors it detects -

ini_set("display_errors", "1");
error_reporting(E_ALL);

Link to comment
https://forums.phpfreaks.com/topic/190522-session-problem/#findComment-1005385
Share on other sites

 

well i added the part for the error reports and still nothing :( no error and empty array

 

Array

(

)

 

:(

 

at the procesor.php when i doo an echo $idi and echo $izbroj i get the correct values i want

 

why does then

 

$_SESSION[$idi]=$izbroj;

 

doesn't want to store them

 

for example $idi 30 and $izbroj 100

 

why does then

 

$_SESSION[$idi]=$izbroj;

 

not equal/result

 

$_SESSION['30']=100;

 

if my values are $idi 30 and $izbroj 100 as the echo prompt right values at procesor.php

 

 

Link to comment
https://forums.phpfreaks.com/topic/190522-session-problem/#findComment-1005424
Share on other sites

 

okay next prob :)

 

i have now in session

 

$_session['2']=30;

$_session['8']=40;

$_session['12']=10;

$_session['10']=5;

$_session['22']=3;

 

first are the id's of the products and the quantity

how can i know how much of them is stored so i can print them in a table ?

 

 

Link to comment
https://forums.phpfreaks.com/topic/190522-session-problem/#findComment-1007405
Share on other sites

 

i have them in a

 

$_session['products']['2']=30;

$_session['products']['8']=40;

$_session['products']['12']=10;

$_session['products']['10']=5;

$_session['products']['22']=3;

 

 

how can i print them out like a order list so the visitor can see what have he added to the basket

 

 

Link to comment
https://forums.phpfreaks.com/topic/190522-session-problem/#findComment-1007413
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.