Jump to content


Photo

Session passing variable - I cant get it to work! Reward for person who fixes it


  • Please log in to reply
4 replies to this topic

#1 mjurmann

mjurmann
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts

Posted 06 October 2006 - 05:21 PM

All I want to do is take information from a form, spit it out on the next page (an information confirmation page), and then if all of their information is correct, allow them to submit the information.  No matter what I do, I can't get it to work. Here is the code from the form page:


<?php session_start();

require_once('../Connections/mrptest.php');

$firstName = $_POST['firstName'];





$_SESSION["apartComplexName"] = $_GET['apartComplexName'];
$_SESSION["apart_id"] = $_GET['apart_id'];
$_SESSION['firstName'] = $firstName;
$_SESSION['lastName'] = $_POST['lastName'];
$_SESSION["apartmentNum"] = $_POST['apartmentNum'];
$_SESSION["emailAddress"] = $_POST['emailAddress'];
$_SESSION["userName"] = $_POST['userName'];
$_SESSION["pwd"] = $_POST['pwd'];
$_SESSION["userGroup"] = $_POST['userGroup'];



?>

Here is the code on the 2nd page:

<?php session_start();
 require_once('../Connections/mrptest.php');


   if( !isset( $_SESSION ) ) { session_start(); }
   if( isset( $_SESSION['REMOTE_ADDR'] ) && $_SESSION['REMOTE_ADDR'] != $_SERVER['REMOTE_ADDR'] )
   { session_regenerate_id(); $_SESSION['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR']; }
   if( !isset( $_SESSION['REMOTE_ADDR'] ) ) { $_SESSION['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR']; }


 $_SESSION['firstName'] = $_POST['firstName'];


// *** Redirect if username exists
$MM_flag="MM_insert";


function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "frm_register_confirm")) {
  $insertSQL = sprintf("INSERT INTO tbl_users (firstName, lastName, apartmentNum, emailAddress, userName, pwd, userGroup) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                    
					   GetSQLValueString($_SESSION['firstName'], "text"),
                       GetSQLValueString($_SESSION['lastName'], "text"),
                       GetSQLValueString($_SESSION['apartmentNum'], "text"),
                       GetSQLValueString($_SESSION['emailAddress'], "text"),
                       GetSQLValueString($_SESSION['userName'], "text"),
                       GetSQLValueString($_SESSION['pwd'], "text"),
                       GetSQLValueString($_SESSION['userGroup'], "text"));

  mysql_select_db($database_mrptest, $mrptest);
  $Result1 = mysql_query($insertSQL, $mrptest) or die(mysql_error());

  $insertGoTo = "registered.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
AND here is how I have the form set up on the second page. NOTE: These fields are not editable, they are just PHP ECHOS, but not in edittable text areas:

<form id="frm_register_confirm" name="frm_register_confirm" method="POST" action="<?php echo $editFormAction; ?>" >
                              <table width="75%" border="0" align="center" cellpadding="6" cellspacing="4">
                                <tr>
                                  <td width="36%"><div align="left">Name (First): </div></td>
                                  <td width="64%"><label>
                                    <div align="left"><?php echo $_SESSION['$firstName']?>
</div>
                                  </label></td>
                                </tr>
                                <tr>
                                  <td><div align="left">Name (Last): </div></td>
                                  <td><label>
                                    <div align="left">
                                    <?php echo $_POST['lastName']?>
                                      </div>
                                  </label></td>
                                </tr>
                                <tr>
                                  <td><div align="left">Apartment Complex Name: </div></td>
                                  <td><div align="left"><?php echo $_SESSION['apartComplexName']?></div></td>
                                </tr>
                                <tr>
                                  <td><div align="left">Apartment Complex ID: </div></td>
                                  <td><label>
                                  <div align="left"><?php echo $_SESSION['apart_id']?></div>
                                  </label></td>
                                </tr>
                                <tr>
                                  <td><div align="left">Apartment Number: </div></td>
                                  <td><label>
                                    <div align="left">
                                      <?php echo $_POST['apartmentNum']?>
                                      </div>
                                  </label></td>
                                </tr>
                                <tr>
                                  <td><div align="left">E-mail: </div></td>
                                  <td><label>
                                    <div align="left">
                                      <?php echo $_POST['emailAddress']?>
                                      </div>
                                  </label></td>
                                </tr>
								 <tr>
                                  <td><div align="left">Username: </div></td>
                                  <td><label>
                                    <div align="left">
                                     <?php echo $_POST['userName']?>
                                    </div>
                                  </label></td>
                                </tr>
                                <tr>
                                  <td><div align="left">Password:</div></td>
                                  <td><label>
                                    <div align="left">
                                     <?php echo $_POST['pwd']?>
                                      </div>
                                  </label></td>
                                </tr>
                                
                                <tr>
                                  <td><div align="left">
                                    <input name="userGroup" type="hidden" id="userGroup" value="registeredMember" />
                                    <br />
                                    <br />
                                    <br />
</div></td>
                                  <td><div align="left">
                                    <label>
                                    <input name="reg_submit" type="submit" id="reg_submit" onclick="MM_validateForm('firstName','','R','lastName','','R','apartmentNum','','R','emailAddress','','RisEmail','userName','','R','pwd','','R','pwdRepeat','','R');return document.MM_returnValue" value="Confirm" />
                                    </label>
</div></td>
                                </tr>
                              </table>
					          <input type="hidden" name="MM_insert" value="frm_register_confirm">
						      <br />
						      <br />
						      <br />
						      <br />
						      <br />
						      <br />
						  </form>

I am willing to Paypal someone $20 if they can help me figure this out. I'm sure its not even a big deal, I just have to get this figured out.

When I submit the 2nd page, I get errors that say "firstName Column cannot be null". I try to ECHO out the Session variables into the form, but they do not show up on the page. It is almost as if they session information is not passing through.

EDIT by zanus: we do have CODE tags for long snippets like that

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 06 October 2006 - 05:32 PM

there shouldn't be a variable in the session value
$_SESSION['firstname'];
not
$_SESSION['$firstname']

First thing i notice will look at rest

Ray



#3 mjurmann

mjurmann
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts

Posted 06 October 2006 - 05:42 PM

Ray, I don't see in my code where I had $_SESSION['$firstname']

#4 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 06 October 2006 - 05:45 PM

Ray, I don't see in my code where I had $_SESSION['$firstname']


well what's this

<div align="left">Name (First): </div></td>
                                  <td width="64%"><label>
                                    <div align="left"><?php echo $_SESSION['$firstName']?>
</div>
                                  </label>


btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#5 mjurmann

mjurmann
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts

Posted 06 October 2006 - 05:47 PM

Oh ok, thank you, I missed that...Still obviously not working.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users