How to store selected dropdown value into session variable and display on another page [duplicate]









up vote
0
down vote

favorite













This question already has an answer here:



  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers



I can't put whole page's code so just I'm putting only about session variable code. So code divide in to 3 page



Error is I'm getting in displaye.php i.e Undefined index: size



select-size.php



<?php session_start();
include 'connection.php';?>

<label for="size">size</label>
<select class="form-control" id="size" name="size">
<option>Chooze size</option>
<option value="s" ><?php echo $row['s_size']; ?></option>
<option value="m" ><?php echo $row['m_size']; ?></option>
<option value="l" ><?php echo $row['l_size']; ?></option>
<option value="xl" ><?php echo $row['xl_size']; ?></option>
<option value="xxl" ><?php echo $row['xxl_size']; ?></option>
</select>

<a href="save-size?id=<?php echo $row['id']; ?>"> <button class="btn btn-primary" ><i class="icon-bag"></i> Add to Cart</button> </a>



  1. savesize.php



    <?php
    session_start();
    $_SESSION['size'] = $_POST['size'];
    // $_SESSION['size'] = "some masssage "; -- if i wrote msg instead of passing selected value its shows on output page
    ?>


3.displaysize.php



<?php
session_start();
//info message
if(isset($_SESSION['size'])) ?>
<h2> size: <?php echo $_SESSION['size']; ?> </h2>
<?php

?>









share|improve this question















marked as duplicate by Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 23 at 13:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • where is your form tag in HTML?
    – Mohammad Ali Taqvazadeh
    Nov 10 at 10:56














up vote
0
down vote

favorite













This question already has an answer here:



  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers



I can't put whole page's code so just I'm putting only about session variable code. So code divide in to 3 page



Error is I'm getting in displaye.php i.e Undefined index: size



select-size.php



<?php session_start();
include 'connection.php';?>

<label for="size">size</label>
<select class="form-control" id="size" name="size">
<option>Chooze size</option>
<option value="s" ><?php echo $row['s_size']; ?></option>
<option value="m" ><?php echo $row['m_size']; ?></option>
<option value="l" ><?php echo $row['l_size']; ?></option>
<option value="xl" ><?php echo $row['xl_size']; ?></option>
<option value="xxl" ><?php echo $row['xxl_size']; ?></option>
</select>

<a href="save-size?id=<?php echo $row['id']; ?>"> <button class="btn btn-primary" ><i class="icon-bag"></i> Add to Cart</button> </a>



  1. savesize.php



    <?php
    session_start();
    $_SESSION['size'] = $_POST['size'];
    // $_SESSION['size'] = "some masssage "; -- if i wrote msg instead of passing selected value its shows on output page
    ?>


3.displaysize.php



<?php
session_start();
//info message
if(isset($_SESSION['size'])) ?>
<h2> size: <?php echo $_SESSION['size']; ?> </h2>
<?php

?>









share|improve this question















marked as duplicate by Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 23 at 13:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • where is your form tag in HTML?
    – Mohammad Ali Taqvazadeh
    Nov 10 at 10:56












up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers



I can't put whole page's code so just I'm putting only about session variable code. So code divide in to 3 page



Error is I'm getting in displaye.php i.e Undefined index: size



select-size.php



<?php session_start();
include 'connection.php';?>

<label for="size">size</label>
<select class="form-control" id="size" name="size">
<option>Chooze size</option>
<option value="s" ><?php echo $row['s_size']; ?></option>
<option value="m" ><?php echo $row['m_size']; ?></option>
<option value="l" ><?php echo $row['l_size']; ?></option>
<option value="xl" ><?php echo $row['xl_size']; ?></option>
<option value="xxl" ><?php echo $row['xxl_size']; ?></option>
</select>

<a href="save-size?id=<?php echo $row['id']; ?>"> <button class="btn btn-primary" ><i class="icon-bag"></i> Add to Cart</button> </a>



  1. savesize.php



    <?php
    session_start();
    $_SESSION['size'] = $_POST['size'];
    // $_SESSION['size'] = "some masssage "; -- if i wrote msg instead of passing selected value its shows on output page
    ?>


3.displaysize.php



<?php
session_start();
//info message
if(isset($_SESSION['size'])) ?>
<h2> size: <?php echo $_SESSION['size']; ?> </h2>
<?php

?>









share|improve this question
















This question already has an answer here:



  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers



I can't put whole page's code so just I'm putting only about session variable code. So code divide in to 3 page



Error is I'm getting in displaye.php i.e Undefined index: size



select-size.php



<?php session_start();
include 'connection.php';?>

<label for="size">size</label>
<select class="form-control" id="size" name="size">
<option>Chooze size</option>
<option value="s" ><?php echo $row['s_size']; ?></option>
<option value="m" ><?php echo $row['m_size']; ?></option>
<option value="l" ><?php echo $row['l_size']; ?></option>
<option value="xl" ><?php echo $row['xl_size']; ?></option>
<option value="xxl" ><?php echo $row['xxl_size']; ?></option>
</select>

<a href="save-size?id=<?php echo $row['id']; ?>"> <button class="btn btn-primary" ><i class="icon-bag"></i> Add to Cart</button> </a>



  1. savesize.php



    <?php
    session_start();
    $_SESSION['size'] = $_POST['size'];
    // $_SESSION['size'] = "some masssage "; -- if i wrote msg instead of passing selected value its shows on output page
    ?>


3.displaysize.php



<?php
session_start();
//info message
if(isset($_SESSION['size'])) ?>
<h2> size: <?php echo $_SESSION['size']; ?> </h2>
<?php

?>




This question already has an answer here:



  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers







php session session-cookies






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 11:25









Shiladitya

9,39391830




9,39391830










asked Nov 10 at 10:49









suraj joshi

15




15




marked as duplicate by Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 23 at 13:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 23 at 13:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • where is your form tag in HTML?
    – Mohammad Ali Taqvazadeh
    Nov 10 at 10:56
















  • where is your form tag in HTML?
    – Mohammad Ali Taqvazadeh
    Nov 10 at 10:56















where is your form tag in HTML?
– Mohammad Ali Taqvazadeh
Nov 10 at 10:56




where is your form tag in HTML?
– Mohammad Ali Taqvazadeh
Nov 10 at 10:56












2 Answers
2






active

oldest

votes

















up vote
1
down vote













Your question is not very clear, something closest to how I understand it is as follows:



select-size.php



 <form method="post" id="form1" name="form1" action="savesize.php">
<label for="size">size</label>
<select class="form-control" id="size" name="size">
<option>Chooze size</option>
<option value="s" >s</option>
<option value="m" >m</option>
<option value="l" >l</option>
<option value="xl" >xl</option>
<option value="xxl" >xxl</option>
</select>
<input type="submit" value="Submit Size" class="submit" >
</form>


savesize.php



 session_start();
if (isset($_POST['size']))
$size = $_POST['size'];

$_SESSION["SizeChosen"] = $size;
header("location: displaysize.php?size=$size");


displaysize.php



 session_start();
$size=$_GET['size'];
?>
<table border="1">
<tr>
<td>Size Chosen:</td><td><?php echo $size ?></td>
</tr>
<tr>
<td>Using Session As Chosen:</td><td><?php echo $_SESSION["SizeChosen"] ?></td>
</tr>
</table>





share|improve this answer




















  • This will allow you to select your session variable from the HTML form and display it on another page.
    – mountain
    Nov 10 at 12:11











  • @suraj joshi give me an upvote, so that someone else can also learn
    – mountain
    Nov 10 at 14:43











  • I read your answer and voteup you...
    – Ferdinando
    Nov 10 at 15:11


















up vote
0
down vote













There is not opening tag here so I'm assuming that you didn't put it or that you forgot to put it on your question. Also, you are trying to submit your form with an anchor tag.



The form tag implies the GET method as default, but in savesize.php you are getting a POST variable.



So you should




  1. add the correct form tag in select-size.php:



    <?php 
    session_start();
    include 'connection.php';
    ?>

    <!-- We are adding here your ID as a GET parameter while sending the other form data as POST -->
    <form action='savesize.php?id=<?php echo $row['id']; ?>' method='POST'>
    <label for="size">size</label>
    <select class="form-control" id="size" name="size">
    <option>Chooze size</option>
    <option value="s" ><?php echo $row['s_size']; ?></option>
    <option value="m" ><?php echo $row['m_size']; ?></option>
    <option value="l" ><?php echo $row['l_size']; ?></option>
    <option value="xl" ><?php echo $row['xl_size']; ?></option>
    <option value="xxl" ><?php echo $row['xxl_size']; ?></option>
    </select>

    <button class="btn btn-primary" type='submit'><i class="icon-bag"></i> Add to Cart</button>
    </form>



  2. Check on savesize.php if the POST value has been submitted:



    <?php
    session_start();
    if(!empty($_POST['size']))
    $_SESSION['size'] = $_POST['size'];

    ?>


Then you should see your size in displaysize.php






share|improve this answer
















  • 1




    got it ,, thanks sir
    – suraj joshi
    Nov 10 at 13:14

















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













Your question is not very clear, something closest to how I understand it is as follows:



select-size.php



 <form method="post" id="form1" name="form1" action="savesize.php">
<label for="size">size</label>
<select class="form-control" id="size" name="size">
<option>Chooze size</option>
<option value="s" >s</option>
<option value="m" >m</option>
<option value="l" >l</option>
<option value="xl" >xl</option>
<option value="xxl" >xxl</option>
</select>
<input type="submit" value="Submit Size" class="submit" >
</form>


savesize.php



 session_start();
if (isset($_POST['size']))
$size = $_POST['size'];

$_SESSION["SizeChosen"] = $size;
header("location: displaysize.php?size=$size");


displaysize.php



 session_start();
$size=$_GET['size'];
?>
<table border="1">
<tr>
<td>Size Chosen:</td><td><?php echo $size ?></td>
</tr>
<tr>
<td>Using Session As Chosen:</td><td><?php echo $_SESSION["SizeChosen"] ?></td>
</tr>
</table>





share|improve this answer




















  • This will allow you to select your session variable from the HTML form and display it on another page.
    – mountain
    Nov 10 at 12:11











  • @suraj joshi give me an upvote, so that someone else can also learn
    – mountain
    Nov 10 at 14:43











  • I read your answer and voteup you...
    – Ferdinando
    Nov 10 at 15:11















up vote
1
down vote













Your question is not very clear, something closest to how I understand it is as follows:



select-size.php



 <form method="post" id="form1" name="form1" action="savesize.php">
<label for="size">size</label>
<select class="form-control" id="size" name="size">
<option>Chooze size</option>
<option value="s" >s</option>
<option value="m" >m</option>
<option value="l" >l</option>
<option value="xl" >xl</option>
<option value="xxl" >xxl</option>
</select>
<input type="submit" value="Submit Size" class="submit" >
</form>


savesize.php



 session_start();
if (isset($_POST['size']))
$size = $_POST['size'];

$_SESSION["SizeChosen"] = $size;
header("location: displaysize.php?size=$size");


displaysize.php



 session_start();
$size=$_GET['size'];
?>
<table border="1">
<tr>
<td>Size Chosen:</td><td><?php echo $size ?></td>
</tr>
<tr>
<td>Using Session As Chosen:</td><td><?php echo $_SESSION["SizeChosen"] ?></td>
</tr>
</table>





share|improve this answer




















  • This will allow you to select your session variable from the HTML form and display it on another page.
    – mountain
    Nov 10 at 12:11











  • @suraj joshi give me an upvote, so that someone else can also learn
    – mountain
    Nov 10 at 14:43











  • I read your answer and voteup you...
    – Ferdinando
    Nov 10 at 15:11













up vote
1
down vote










up vote
1
down vote









Your question is not very clear, something closest to how I understand it is as follows:



select-size.php



 <form method="post" id="form1" name="form1" action="savesize.php">
<label for="size">size</label>
<select class="form-control" id="size" name="size">
<option>Chooze size</option>
<option value="s" >s</option>
<option value="m" >m</option>
<option value="l" >l</option>
<option value="xl" >xl</option>
<option value="xxl" >xxl</option>
</select>
<input type="submit" value="Submit Size" class="submit" >
</form>


savesize.php



 session_start();
if (isset($_POST['size']))
$size = $_POST['size'];

$_SESSION["SizeChosen"] = $size;
header("location: displaysize.php?size=$size");


displaysize.php



 session_start();
$size=$_GET['size'];
?>
<table border="1">
<tr>
<td>Size Chosen:</td><td><?php echo $size ?></td>
</tr>
<tr>
<td>Using Session As Chosen:</td><td><?php echo $_SESSION["SizeChosen"] ?></td>
</tr>
</table>





share|improve this answer












Your question is not very clear, something closest to how I understand it is as follows:



select-size.php



 <form method="post" id="form1" name="form1" action="savesize.php">
<label for="size">size</label>
<select class="form-control" id="size" name="size">
<option>Chooze size</option>
<option value="s" >s</option>
<option value="m" >m</option>
<option value="l" >l</option>
<option value="xl" >xl</option>
<option value="xxl" >xxl</option>
</select>
<input type="submit" value="Submit Size" class="submit" >
</form>


savesize.php



 session_start();
if (isset($_POST['size']))
$size = $_POST['size'];

$_SESSION["SizeChosen"] = $size;
header("location: displaysize.php?size=$size");


displaysize.php



 session_start();
$size=$_GET['size'];
?>
<table border="1">
<tr>
<td>Size Chosen:</td><td><?php echo $size ?></td>
</tr>
<tr>
<td>Using Session As Chosen:</td><td><?php echo $_SESSION["SizeChosen"] ?></td>
</tr>
</table>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 12:09









mountain

299




299











  • This will allow you to select your session variable from the HTML form and display it on another page.
    – mountain
    Nov 10 at 12:11











  • @suraj joshi give me an upvote, so that someone else can also learn
    – mountain
    Nov 10 at 14:43











  • I read your answer and voteup you...
    – Ferdinando
    Nov 10 at 15:11

















  • This will allow you to select your session variable from the HTML form and display it on another page.
    – mountain
    Nov 10 at 12:11











  • @suraj joshi give me an upvote, so that someone else can also learn
    – mountain
    Nov 10 at 14:43











  • I read your answer and voteup you...
    – Ferdinando
    Nov 10 at 15:11
















This will allow you to select your session variable from the HTML form and display it on another page.
– mountain
Nov 10 at 12:11





This will allow you to select your session variable from the HTML form and display it on another page.
– mountain
Nov 10 at 12:11













@suraj joshi give me an upvote, so that someone else can also learn
– mountain
Nov 10 at 14:43





@suraj joshi give me an upvote, so that someone else can also learn
– mountain
Nov 10 at 14:43













I read your answer and voteup you...
– Ferdinando
Nov 10 at 15:11





I read your answer and voteup you...
– Ferdinando
Nov 10 at 15:11













up vote
0
down vote













There is not opening tag here so I'm assuming that you didn't put it or that you forgot to put it on your question. Also, you are trying to submit your form with an anchor tag.



The form tag implies the GET method as default, but in savesize.php you are getting a POST variable.



So you should




  1. add the correct form tag in select-size.php:



    <?php 
    session_start();
    include 'connection.php';
    ?>

    <!-- We are adding here your ID as a GET parameter while sending the other form data as POST -->
    <form action='savesize.php?id=<?php echo $row['id']; ?>' method='POST'>
    <label for="size">size</label>
    <select class="form-control" id="size" name="size">
    <option>Chooze size</option>
    <option value="s" ><?php echo $row['s_size']; ?></option>
    <option value="m" ><?php echo $row['m_size']; ?></option>
    <option value="l" ><?php echo $row['l_size']; ?></option>
    <option value="xl" ><?php echo $row['xl_size']; ?></option>
    <option value="xxl" ><?php echo $row['xxl_size']; ?></option>
    </select>

    <button class="btn btn-primary" type='submit'><i class="icon-bag"></i> Add to Cart</button>
    </form>



  2. Check on savesize.php if the POST value has been submitted:



    <?php
    session_start();
    if(!empty($_POST['size']))
    $_SESSION['size'] = $_POST['size'];

    ?>


Then you should see your size in displaysize.php






share|improve this answer
















  • 1




    got it ,, thanks sir
    – suraj joshi
    Nov 10 at 13:14














up vote
0
down vote













There is not opening tag here so I'm assuming that you didn't put it or that you forgot to put it on your question. Also, you are trying to submit your form with an anchor tag.



The form tag implies the GET method as default, but in savesize.php you are getting a POST variable.



So you should




  1. add the correct form tag in select-size.php:



    <?php 
    session_start();
    include 'connection.php';
    ?>

    <!-- We are adding here your ID as a GET parameter while sending the other form data as POST -->
    <form action='savesize.php?id=<?php echo $row['id']; ?>' method='POST'>
    <label for="size">size</label>
    <select class="form-control" id="size" name="size">
    <option>Chooze size</option>
    <option value="s" ><?php echo $row['s_size']; ?></option>
    <option value="m" ><?php echo $row['m_size']; ?></option>
    <option value="l" ><?php echo $row['l_size']; ?></option>
    <option value="xl" ><?php echo $row['xl_size']; ?></option>
    <option value="xxl" ><?php echo $row['xxl_size']; ?></option>
    </select>

    <button class="btn btn-primary" type='submit'><i class="icon-bag"></i> Add to Cart</button>
    </form>



  2. Check on savesize.php if the POST value has been submitted:



    <?php
    session_start();
    if(!empty($_POST['size']))
    $_SESSION['size'] = $_POST['size'];

    ?>


Then you should see your size in displaysize.php






share|improve this answer
















  • 1




    got it ,, thanks sir
    – suraj joshi
    Nov 10 at 13:14












up vote
0
down vote










up vote
0
down vote









There is not opening tag here so I'm assuming that you didn't put it or that you forgot to put it on your question. Also, you are trying to submit your form with an anchor tag.



The form tag implies the GET method as default, but in savesize.php you are getting a POST variable.



So you should




  1. add the correct form tag in select-size.php:



    <?php 
    session_start();
    include 'connection.php';
    ?>

    <!-- We are adding here your ID as a GET parameter while sending the other form data as POST -->
    <form action='savesize.php?id=<?php echo $row['id']; ?>' method='POST'>
    <label for="size">size</label>
    <select class="form-control" id="size" name="size">
    <option>Chooze size</option>
    <option value="s" ><?php echo $row['s_size']; ?></option>
    <option value="m" ><?php echo $row['m_size']; ?></option>
    <option value="l" ><?php echo $row['l_size']; ?></option>
    <option value="xl" ><?php echo $row['xl_size']; ?></option>
    <option value="xxl" ><?php echo $row['xxl_size']; ?></option>
    </select>

    <button class="btn btn-primary" type='submit'><i class="icon-bag"></i> Add to Cart</button>
    </form>



  2. Check on savesize.php if the POST value has been submitted:



    <?php
    session_start();
    if(!empty($_POST['size']))
    $_SESSION['size'] = $_POST['size'];

    ?>


Then you should see your size in displaysize.php






share|improve this answer












There is not opening tag here so I'm assuming that you didn't put it or that you forgot to put it on your question. Also, you are trying to submit your form with an anchor tag.



The form tag implies the GET method as default, but in savesize.php you are getting a POST variable.



So you should




  1. add the correct form tag in select-size.php:



    <?php 
    session_start();
    include 'connection.php';
    ?>

    <!-- We are adding here your ID as a GET parameter while sending the other form data as POST -->
    <form action='savesize.php?id=<?php echo $row['id']; ?>' method='POST'>
    <label for="size">size</label>
    <select class="form-control" id="size" name="size">
    <option>Chooze size</option>
    <option value="s" ><?php echo $row['s_size']; ?></option>
    <option value="m" ><?php echo $row['m_size']; ?></option>
    <option value="l" ><?php echo $row['l_size']; ?></option>
    <option value="xl" ><?php echo $row['xl_size']; ?></option>
    <option value="xxl" ><?php echo $row['xxl_size']; ?></option>
    </select>

    <button class="btn btn-primary" type='submit'><i class="icon-bag"></i> Add to Cart</button>
    </form>



  2. Check on savesize.php if the POST value has been submitted:



    <?php
    session_start();
    if(!empty($_POST['size']))
    $_SESSION['size'] = $_POST['size'];

    ?>


Then you should see your size in displaysize.php







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 11:39









J0ker98

1379




1379







  • 1




    got it ,, thanks sir
    – suraj joshi
    Nov 10 at 13:14












  • 1




    got it ,, thanks sir
    – suraj joshi
    Nov 10 at 13:14







1




1




got it ,, thanks sir
– suraj joshi
Nov 10 at 13:14




got it ,, thanks sir
– suraj joshi
Nov 10 at 13:14



Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20