Jump to content

$_SESSION var not being passed to next php script


bulrush

Recommended Posts

Summary: I want to pass a value called "grid", which is a key field, to the next php script, so I can edit multiple records having this key "grid".

 

On my first screen/script, "editpartsearch.php", the user chooses a name, which has one grid associated with it. Then the user clicks a submit button (named cmdEdit), which calls a screen/script called "editpart.php".

 

At the end of "editpartsearch.php" I set $_SESSION['grid'] to be the value of $grid, but when "editpart.php" runs, $_SESSION['grid'] is not set. It is blank.

 

Here is the code at the end of "editpartsearch.php".

 

<h2>Proto3: Product/Part Edit Search v.10a</h2>
<p>This screen is used to search for existing products to edit.

<form action="<?php echo 'editpart.php?'.SID; ?>" method="post">

<hr/>
<label for="cbxGroupname">Group name</label>
<select name="cbxGroupname">
<?php
$query="SELECT grid, groupname, basemodel FROM hgroup ORDER BY groupname;";
if (!$result=mysqli_query($dbc,$query))
    {
    $msg=mysql_error();
    echo '</select><p class="error">'.$msg.'<br/>'.$query.'</p>';
    die();
    }
$i=mysqli_num_rows($result);
if ($i<1)
    {
    $msg='</select><p class="error">ERROR: No groups selected: '.$query.'</p>';
    die($msg);
    }

//Combo box showing all group names. 
$done=0;
while ($row = mysqli_fetch_array($result)) 
    {
    $v=$row['groupname'].'#'.$row['basemodel'];
    $s='<option value="'.$v.'"';
    if ($done==0)
        {
        //$s.=' selected'; //Select only first one.
        //$done=1;
        }
    $s.='>'.$v."\n";
    echo $s;
    } 
$_SESSION['grid']=$row['grid']; //Save last grid to send to next form.

?>
</select>

<p>
<p>Commands: <input type="submit" name="cmdEdit" value="Edit">
</form>

<?php
mysqli_close($dbc);
?>
</body>
</html>

 

At the top of "editpart.php" is a bunch of code to save the data if the user clicked the Submit button. Since that is skipped, here is the code immediately after that code, which displays $_SESSION['grid'].

<! editpart.php-------------------------------------------------------->
<?php 
echo 'Session grid: '.$_SESSION['grid'];
?>
<h2>Proto3: Product Edit v.10a</h2>
<p>This screen is used to edit products.

<form action="<?php echo $_SERVER['PHP_SELF'].'?'.SID; ?>" method="post">

<hr/>

 

Any idea why $_SESSION['grid'] is not set in editpart.php? Thanks.

 

p.s. I am a beginner to PHP, so I may have missed something basic. Also, grid stands for "group id".

 

Link to comment
Share on other sites

You are not using session_start() on any page!

 

This. Although he could have submitted page fragments. In that case I would recommend you start by placing this

 

echo $row['grid'];

 

right before you set the session variable. If it shows the expected result then we can go from there. If not then you know that one of two things is wrong (There's something wrong with the record/query or it's not getting to that area in the script.)

 

But do what was suggested first and start your session if not already done.

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.