Jump to content

PHP Sessions


mmophp

Recommended Posts

Hi:I need to store variables to send then between pages. I don't need the variables in a database so I try to send them with sessions. The variables don't seem to be there when I try to get them. What could be the problem. Here are the pages where I store and retrieve the variables.Page 1 (variables stored):<?phpsession_start();$_SESSION['scripture_text'] = $row_scripture['ScriptureText'];$_SESSION['scripture_ref'] = $row_scripture['ScriptureRef'];?>echo statements show that $row_scripture['ScriptureText'] and $row_scripture['ScriptureRef'] have text.Page 2 (variables retrieved):<?phpsession_start();include("includes/config.php");?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head></head><body><table width="100%" align="center" border="0"><tr> <td align="left"><?="«".$_SESSION['scripture_text']."»"?></td> </tr><tr> <td style="font-size: smaller;" align="right"><?=$_SESSION['scripture_ref']?></td> </tr></table></body></html>

Link to comment
Share on other sites

First, unless you know if it works on your server, avoid using the <?= syntax. It's better to write it like this:<?php echo $_SESSION['scripture_ref']; ?>It's longer, but you can guarantee that will work on any server. The short tag syntax only works on servers which have it enabled, but if you use the long syntax it will always work. You can also use this to print out all of the session to check what's there:print_r($_SESSION);

Link to comment
Share on other sites

First, unless you know if it works on your server, avoid using the <?= syntax. It's better to write it like this:<?php echo $_SESSION['scripture_ref']; ?>It's longer, but you can guarantee that will work on any server. The short tag syntax only works on servers which have it enabled, but if you use the long syntax it will always work. You can also use this to print out all of the session to check what's there:print_r($_SESSION);
Thanks! This seems to be the problem. The echo statements will work in this situation. What about other places like the ones below.a. <input type="text" name="reservation_date" value="<?=$_POST['reservation_date'];?>" readonly="">b. <td class="st1"><input name="email" type="text" class="v_email" id="email" value="<?=$_GET['email'];?>" /> <span style="padding-left: 3px;"> <input type="button" name="button" id="button" value="Get my Information" onclick="getacctt()" /> </span></td>c. <?if ($rows > 0){?>d. <?php$i=0;while($results = mysql_fetch_assoc($exec)){?> <?php $i++; ?> <tr><td><?=date("m/d/Y", strtotime($results['PledgeDate'])) ?></td><?echo "Anonymous: ".$results['Anonymous']."<br/>";if($results['Anonymous'] == 1 ) { ?> <td>anonymous</td><? } else {?> <td><?=$results['Firstname']." ".$results['Lastname'];?></td><? } ?> <td><?=$results['City']." ".$results['State']." ".$results['Country'];?></td> <td><?=$results['PledgeDesc'];?></td> <td><?=$results['LocationChurch']." ".$results['LocationCity']." ".$results['LocationState']." ".$results['LocationCountry'];?></td> </tr><?php }//end of whileOne comment, when I replace <? in scenario c. with <?php I get a 500 page error. The <?php don't seem to be nested. I thought this might be that within the table HTML doesn't like it. But this seems OK in other tables.Thanks.
Link to comment
Share on other sites

It doesn't have anything to do with the HTML, it's best to replace all short tags with the long tags. If it gives you a syntax error, that probably means that the newly-activated PHP code has an error somewhere, when it had a short tag it wasn't even executing the code. Adding the long tag may expose an error that already existed.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...