1

Hi

I have a question. I haven't try this yet but rather have someone tell me that it will work or not.

For example I have this let's call this 1.php file

1.php has these two categories

SKU: <?php echo stripslashes($row1['sku']);?>
Item ID: <?php echo stripslashes($row1['itid']);?>

I want to submit these two categories to 2.php, 3.php and appear on 4.php (final)

1.php - Once I submited this form it will go to 2.php

Now I'm on 2.php

Can I used this

<input name="sku" type="hidden" id="sku" value="yes"/>
<input name="itid" type="hidden" id="itid" value="yes"/>

To submited to 3.php and finally appear on 4.php?

I know this sound dumb but can this work?

I really do appreciate if someone explained to me how this works!

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by LastMitch
2

Hi,

Yes you can do it.. here is sample. This example demonstrate how to assign array in session.

1.php

<?php
session_start();
   ## page one
   $sku = "12345678_SKU";
   $itemID = "580007";
   ## make sure the above are not empty
   if((!empty($sku))&&(!empty($itemID))){

   $itemAr = array( $sku, $itemID );
   $_SESSION['items'] = $itemAr;

   }

   echo '<a href="2.php">Go to page 2</a>';
?>

2.php . I am not a big fan of php shorthand tags, but I will use it here..

 <?php
   ## filename 2.php
   session_start();
   ## let's access items in the session and move them to form input
?>
   <form method="post" action="3.php">
    <p>
   <label>SKU</label>
   <input type="text" name="sku" value="<?=$_SESSION['items'][0]?>"/><br/>
   </p>
   <p>
   <label>Item ID</label>
   <input type="text" name="itid" value="<?=$_SESSION['items'][1]?>"/><br/>
   </p>
   <p>
   <input type="submit" name="submit" value="Next"/><br/>
   </p>
   </form>
   <!-- end of form -->

3.php This file demonstrate how we can unset session for specific array assign to it, and then assign a new set of array.

 <?php
   ## filename 3.php
   session_start();

   ## since that this page is now relying on the items submitted in the form, we can unset our session['items']


   if((isset($_POST['submit']))&& (!empty($_POST['sku']))&& (!empty($_POST['itid']))){
   ## unset session from two previous page to set these form items
   ## if browser is going to go back and forth between pages, do not unset the first session, instead create a new one.
   unset($_SESSION['items']);

   ## I added a suffic -> _two on the posted items, for 4.php checkpoint. We want to make sure the session has been unset if wa
   ## we want it unset.
   $sku1 = $_POST['sku']."_two";
   $itid = $_POST['itid']."_two";

   echo $sku1."<br/>";
   echo $itid."<br/>";
   ## you can either assign to session
   $item2 = array($sku1,$itid);
   $_SESSION['item2'] = $item2;

   }
 ?>
 <a href="4.php">page 4</a><br/>

4.php The items from 3.php are also passed on to this page. I just added a suffix _two to verify that the session['items'], can be unset, whenever we want it . However, it is all up to you. If you will be allowing user to go back and forth between pages, you need to use the session['items'] .

 <?php
   ## filename 4.php
   session_start();
   echo "These items were carried from 3.php<br/>";
   echo "Sku from page 3:  ".$_SESSION['item2'][0]."<br/>";
   echo "Item ID from page 3: ".$_SESSION['item2'][1]."<br/>";
?>

There you have it an example using session, unset session, and acessing the array in the session.

Please forgive my excessive use of parenthesis... I cannot help it, because I used to write calculators, and I was heavily envolved in electron tube amplifier output transformer calculator design based on php and mysql. Without those isolating parenthesis, my approximation will not be able to be reproduce by others using the same equation by way PEMDAS convention.

Edited by veedeoo: more info added

Votes + Comments
Thanks for the example!
1

@ P0lT10n

Thanks for the replay! But I need some code for me to understand how it works. But Thanks!

Edited by LastMitch: grammer

1

@ veedeoo (The Future Rhode Scholar)

I reading the script and it's very basic and I haven't compile it yet. I just need a few lines from the script you wrote and modify to my script.

I really do appreciated your time answering my question and I'll get back to soon when I'm finish running it.

Thanks

3

@Rhode Scholar (veedeoo)

Thanks. You help me resolve this simple issue! You're a bit too young to drink or gamble or go to stripclubs. You can't do anything but you keep up the good work!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.