Jump to content

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


mjurmann

Recommended Posts

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:


[code]
<?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'];



?>
[/code]

Here is the code on the 2nd page:

[code]
<?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));
}
[/code]
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:

[code]
<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>
[/code]

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
Link to comment
Share on other sites

[quote author=mjurmann link=topic=110717.msg448148#msg448148 date=1160156521]
Ray, I don't see in my code where I had $_SESSION['$firstname']
[/quote]

well what's this
[quote]
<div align="left">Name (First): </div></td>
                                  <td width="64%"><label>
                                    <div align="left"><?php echo [b]$_SESSION['$firstName'][/b]?>
</div>
                                  </label>
[/quote]
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.