kannu Posted March 26, 2009 Share Posted March 26, 2009 hello, i am a newbie so please excuse if this is an obvious question but after 3 hours of research and trying different syntax, i cannot figure this out. i have the following code in the body section which works perfectly, which basically generates a string text. <td class="decsription_bg2"><b><span id="custom_carat"><?=$row_prod['total_carat_weight']?></span> Carat </td> What I want to do is to store the text generated by the above code to a variable which i can pass alont to the next page. what should i add after the above line, to store this in a variable and to pass it along the next page. the page is currently using "post" method. any help would be really appreciated. thanks Quote Link to comment Share on other sites More sharing options...
FaT3oYCG Posted March 26, 2009 Share Posted March 26, 2009 <?php $_POST['total_carat_weight'] = $row_prod['total_carat_weight']; ?> Quote Link to comment Share on other sites More sharing options...
waynewex Posted March 26, 2009 Share Posted March 26, 2009 It's usually better not to use short tags such as <? Use <?php and ?> Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted March 26, 2009 Share Posted March 26, 2009 I would suggest 3 choices either using $_GET, $_COOKIE, or $_SESSION of the 3 i would go with $_SESSION How your going to do this I would suggest the easiest way would be since you want to pass it on from page to page is on the very top of your page above the HTML tag add <?php session_start(); ?> now where you have your code to randomly generate or generate how ever you do. Put something to the effect of: <?php if(!$_SESSION['carrot_weight']) { /* put your generator here */ } else { $_SESSION['carrot_weight'] = $row_prod['total_carat_weight']; } ?> then in your Table you going to put <?php echo $_SESSION['carrot_weight']; ?> instead of <?=$row_prod['total_carat_weight']?> Also rule of thumb outside of your question try not to use an open tag like <? without the php next to it, some server most rather don't support that and will error your coding. So try to always do <?php for the beginning of your tags.. I also say this assuming your not using a form as I dont see form elements in your initial post, however this can be apply to forms as well.. Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted March 26, 2009 Share Posted March 26, 2009 whoops forgot to mention if you want to get rid of the $_SESSION variable you can either do unset($_SESSION['carot_weight']); or session_destroy(); if you have session data on the site in use else where though i wouldnt suggest destroy as its reseting all sessions to null Quote Link to comment Share on other sites More sharing options...
kannu Posted March 27, 2009 Author Share Posted March 27, 2009 hello thank you guys for taking time to help me out, but sorry if i was not clear in my initial post. the <td class="decsription_bg2"><b><span id="custom_carat"><?=$row_prod['total_carat_weight']?></span> Carat <span id="custom_carat12"><?=$row_prod['total_carat_weight3']?></td> the above is not the complete code, but the whole line is comprised of various variables which combine together to produce a string text, which changes based on user selection of different options. i want to capture and assign the entire final string text produced by the above, and assign it to one variable. how can i do the same. thanks Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 27, 2009 Share Posted March 27, 2009 If you want to pass the contents of a variable from one page to another probably the best way is to use a session variable as mentioned above. Set a session variable: $_SESSION['myvar']=$row_prod['total_carat_weight']; Read the session variable: $totalCaratWeight=$_SESSION['myvar']; If you're linking from one page to another you can pass it in the URL (less secure) <a href="nextpage.php?carat=<?=$row_prod['total_carat_weight']?>">next page</a> From nextpage.php get the value with $_GET: $totalCaratWeight=$_GET['carat']; If you're passing integers I'd advise this: $totalCaratWeight=intval($_GET['carat']); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.