3
Contributors
21
Replies
78
Views
4 Years
Discussion Span
Last Post by broj1
0

The above code returns blank in the Last_Name Field...please help on how to retain Field Data

0

Just one question: why do you store the $_POST array in session? What is the exact purpose of that?

Tipically the code goes like that:

  • you have a form wrapped within <form> and </form> tags (you do not have that, any reason why not?)
  • in the opennig <form> tag you declare an action and a method attributes

    • the action is the name of the page where the result will be show - you also do the database query on tnis page
    • the method is the HTTP method of sending the form data to the server (POST is safer and has more capacity, GET is a bit less safe but can be bookmarked since the values are visible in URL)
  • form aslo has a submit button which is input type="submits" which actuall triggers the sending of data to the server and redirects to the action page
  • once on action page you check whether all needed values are present in the $_POST or $_GET array
  • if yes you do a SQL query and display the results
  • id no you let user know (i.e. by displaying an error message)

Certainly there are other variations like:
- having results displayed on the same page
- using ajax to avoid any reloading of the page
- autosubmitting the form using javascript etc

Please let us know what exactly are your goals.

0

I was told to...What I'm trying to do is a table lookup "it works" but when i fill out last _name field then do a lookup, the field goes blank...I'm need to retain the field data, instead it goes blank and i loose what i entered...thanks

0

Post this debug code after assigning to $_SESSION:

<?php
session_start();
$_SESSION['form'] = $_POST; 

// DEBUG - display the contents of the session array
die(print_r($_SESSION, 1));

?>

It will display the contents of the session variable and stop the script. Please post the output. Now check if $_SESSION['form']['Last_Name'] exists. If not then it does not exist in $_POST either.

Edited by broj1

0

bro...This was the output...Array ( [form] => Array ( ) )
Ok could you give me a better example thanks

0

This means $_SESSION['form'] is not existing so $_SESSION['form']['Last_Name'] is not existing so you can't use it. It also means that $_POST is not set which in turn means the form did not get posted. Do you have a submit button in the form <input type="submit">?

I still do not understand what is the purpose of assigning $_POST to $_SESSION.

I will try to give you an example of how I would do it but I am not sure exactly if this is what you want. But can you post complete code first.

Edited by broj1

0
<?php require_once('Connections/Leadbook.php'); ?>
<?php

session_start();
$_SESSION['form'] = $_POST; 
// DEBUG - display the contents of the session array
die(print_r($_SESSION, 1));


$_SESSION['form'] = $_POST;


if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO Leads (LeadNo, `Date`, `Last Name`, Address, City, `State`, `Zip Code`, Phone, `Apt date`, SalesNo, JobNo, `First`, Spouse, Amount, AdNo, Coments, `Call Back`, Active, Email, `Time`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['LeadNo'], "int"),
                       GetSQLValueString($_POST['Date'], "date"),
                       GetSQLValueString($_POST['Last_Name'], "text"),
                       GetSQLValueString($_POST['Address'], "text"),
                       GetSQLValueString($_POST['LookupCity'], "text"),
                       GetSQLValueString($_POST['State'], "text"),
                       GetSQLValueString($_POST['Zip_Code'], "text"),
                       GetSQLValueString($_POST['Phone'], "text"),
                       GetSQLValueString($_POST['Apt_date'], "date"),
                       GetSQLValueString($_POST['LookupSalesman'], "int"),
                       GetSQLValueString($_POST['LookupJobNo'], "int"),
                       GetSQLValueString($_POST['First'], "text"),
                       GetSQLValueString($_POST['Spouse'], "text"),
                       GetSQLValueString($_POST['Amount'], "double"),
                       GetSQLValueString($_POST['LookupAdNo'], "int"),
                       GetSQLValueString($_POST['Comments'], "text"),
                       GetSQLValueString($_POST['CallBack'], "text"),
                       GetSQLValueString(isset($_POST['Active']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['Email'], "text"),
                       GetSQLValueString($_POST['Time'], "date"));

  mysql_select_db($database_Leadbook, $Leadbook);
  $Result1 = mysql_query($insertSQL, $Leadbook) or die(mysql_error());

  $insertGoTo = "LeadTable.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

$maxRows_fmLeads = 1;
$pageNum_fmLeads = 0;
if (isset($_GET['pageNum_fmLeads'])) {
  $pageNum_fmLeads = $_GET['pageNum_fmLeads'];
}
$startRow_fmLeads = $pageNum_fmLeads * $maxRows_fmLeads;

mysql_select_db($database_Leadbook, $Leadbook);
$query_fmLeads = "SELECT * FROM Leads";
$query_limit_fmLeads = sprintf("%s LIMIT %d, %d", $query_fmLeads, $startRow_fmLeads, $maxRows_fmLeads);
$fmLeads = mysql_query($query_limit_fmLeads, $Leadbook) or die(mysql_error());
$row_fmLeads = mysql_fetch_assoc($fmLeads);

if (isset($_GET['totalRows_fmLeads'])) {
  $totalRows_fmLeads = $_GET['totalRows_fmLeads'];
} else {
  $all_fmLeads = mysql_query($query_fmLeads);
  $totalRows_fmLeads = mysql_num_rows($all_fmLeads);
}
$totalPages_fmLeads = ceil($totalRows_fmLeads/$maxRows_fmLeads)-1;

mysql_select_db($database_Leadbook, $Leadbook);
$query_fmSalesman = "SELECT * FROM Salesman ORDER BY Salesman.Salesman";
$fmSalesman = mysql_query($query_fmSalesman, $Leadbook) or die(mysql_error());
$row_fmSalesman = mysql_fetch_assoc($fmSalesman);
$totalRows_fmSalesman = mysql_num_rows($fmSalesman);

mysql_select_db($database_Leadbook, $Leadbook);
$query_fmAdveriser = "SELECT * FROM advertising ORDER BY Advertiser ASC";
$fmAdveriser = mysql_query($query_fmAdveriser, $Leadbook) or die(mysql_error());
$row_fmAdveriser = mysql_fetch_assoc($fmAdveriser);
$totalRows_fmAdveriser = mysql_num_rows($fmAdveriser);

mysql_select_db($database_Leadbook, $Leadbook);
$query_fmJob = "SELECT * FROM Job ORDER BY Job.`Description`";
$fmJob = mysql_query($query_fmJob, $Leadbook) or die(mysql_error());
$row_fmJob = mysql_fetch_assoc($fmJob);
$totalRows_fmJob = mysql_num_rows($fmJob);

mysql_select_db($database_Leadbook, $Leadbook);
$query_fmCity = "SELECT * FROM Zip ORDER BY Zip.City";
$fmCity = mysql_query($query_fmCity, $Leadbook) or die(mysql_error());
$row_fmCity = mysql_fetch_assoc($fmCity);
$totalRows_fmCity = mysql_num_rows($fmCity);

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>New Lead</title>
<script src="assets/CalendarPopup.js" type="text/javascript" ></script>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="assets/Col2text.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<link href="assets/Addresstext.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#form1 fieldset {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    border-right-width: 1px;
    border-bottom-width: 1px;
    border-right-style: solid;
    border-bottom-style: solid;
    border-right-color: #729E91;
    border-bottom-color: #729E91;
    padding-top: 20px;
    padding-left: 20px;
    margin-bottom: 20px;
    background-color: #EBEBEB;
    color: #444;
    font-size: .8em;
    border-top-style: none;
    border-left-style: none
}
#form1 legend {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    background-color: #EBEBEB;
    letter-spacing: .01em;
    margin-top: 0.5px;
    padding-top: 5px;
    padding-right: 10px;
    padding-bottom: 5px;
    padding-left: 10px;
    font-size: 0.08em;
    text-transform: uppercase
}
#form1 #fieldcolor, #form1 #legendcolor {
    background-color: #CCCCCC
}
-->
</style>
<!--[if IE 5]>
<style type="text/css"> 
/* place css box model fixes for IE 5* in this conditional comment */
.twoColFixRtHdr #sidebar1 { width: 220px; }
</style>
<![endif]-->
<!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.twoColFixRtHdr #sidebar1 { padding-top: 30px; }
.twoColFixRtHdr #mainContent { zoom: 1; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->

<script type="text/javascript">
var cal = new CalendarPopup()

function check(RadioGroup1)
{document.getElementById("Phone").value=RadioGroup1
}

</script>
</head>
<body class="twoColFixRtHdr">
<div id="container">
  <header id="header">
    <hgroup>
      <h1>&nbsp;</h1>
      <p>&nbsp;</p>
    </hgroup>
    <nav>
      <ul id="MenuBar1" class="MenuBarHorizontal">
        <li><a href="index.php">Home</a> </li>
        <li><a href="#" class="MenuBarItemSubmenu">New</a>
          <ul>
            <li><a href="LeadInsert.php">New Lead</a></li>
            <li><a href="CustInsert.php">New Customer</a></li>
          </ul>
        </li>
        <li><a class="MenuBarItemSubmenu" href="#">View</a>
          <ul>
            <li><a href="LeadTable.php">Lead Listing</a> </li>
            <li><a href="CustTable.php">Customer Listing</a></li>
            <li><a href="ContactsTable.php">Contact Listing</a></li>
            <li><a href="EmployeeTable.php">Employee Listing</a></li>
            <li><a href="VendorTable.php">Vendor Listing</a></li>
            <li><a href="TaskTable.php">Task Listing</a></li>
            <li><a href="#" class="MenuBarItemSubmenu">Tools</a>
              <ul>
                <li><a href="ZipTable.php">Zip Code Listing</a></li>
                <li><a href="SalesmanTable.php">Salesman listing</a></li>
                <li><a href="ProductsTable.php">Product Listing</a></li>
                <li><a href="AdvertiseTable.php">Advertising Listing</a></li>
              </ul>
            </li>
          </ul>
        </li>
        <li><a href="Snapshot.php">Snapshot</a></li>
        <li><a href="#">Report</a></li>
      </ul>
    </nav>
    <p>&nbsp;</p>
    <!-- end #header --></header>
  <section id="sidebar1">
    <h3> Records <?php echo ($startRow_fmLeads + 1) ?> to <?php echo min($startRow_fmLeads + $maxRows_fmLeads, $totalRows_fmLeads) ?> of <?php echo $totalRows_fmLeads ?></h3>
    <p>&nbsp;</p>
    <!-- end #sidebar1 --></section>
  <aside id="mainContent">
    <hgroup>
      <h1>&nbsp; </h1>
      <h1 class="stylered">Admin:Lead Insert</h1>
      <h3>Complete the form below to add a new lead type</h3>
    </hgroup>
    <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
      <fieldset>
        <legend>Leadinfo</legend>
        <table width="60%" border="0" align="left">
          <tr valign="baseline">
            <td width="69" align="right" nowrap="nowrap">Date:</td>
            <td width="315"><input type="date" name="Date" id="Date" value="<?php echo date("Y-m-d"); ?>" size="20" />
              <a href="#" onclick="cal.select(document.forms[0].Date,'anchor1','yyyy-MM-dd'); return false;" name="anchor1" id="anchor1">select</a></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">First:</td>
            <td><input type="text" name="First" placeholder="first name" value="" size="20" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Last Name:</td>
            <td>

            <input type="text" name="Last_Name" id="Last_Name" autofocus value="<?php echo $_SESSION['form']; ?>" placeholder="last name" size="32" /></td>

          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Address:</td>
            <td><input type="text" name="Address" placeholder="address" value="" size="32" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">City:</td>
            <td><select name="LookupCity" id="LookupCity">
                <option value="" <?php if (!(strcmp("", $_GET['City']))) {echo "selected=\"selected\"";} ?>>Select from menu</option>
                <?php do { ?>
                <option value="<?php echo $row_fmCity['City']?>"<?php if (!(strcmp($row_fmCity['City'], $_GET['City']))) {echo "selected=\"selected\"";} ?>><?php echo $row_fmCity['City']?></option>
                <?php
} while ($row_fmCity = mysql_fetch_assoc($fmCity));
$rows = mysql_num_rows($fmCity);
if($rows > 0) {
mysql_data_seek($fmCity, 0);
$row_fmCity = mysql_fetch_assoc($fmCity); } ?>
              </select>
              <a href="ZipLookup.php">select</a></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">State:</td>
            <td><input type="text" name="State" id="State" placeholder="NY" value="<?php echo $_GET['State']; ?>" size="5"/>
              <input type="text" name="Zip_Code" placeholder="zip code" value="<?php echo $_GET['Zip']; ?>" size="10" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Phone:</td>
            <td><input name="Phone" type="tel" placeholder="(555)555-5555" id="Phone" value="<?php echo '(516)'; ?>" size="15" />
              <br />
              <input name="RadioGroup1" type="radio" onclick="check(this.value)"  value="(516)" checked="checked"  />
              <label>(516)</label>
              <input name="RadioGroup1" type="radio" onclick="check(this.value)" value="(631)"  />
              <label>(631)</label>
              <input name="RadioGroup1" type="radio" onclick="check(this.value)"  value="(718)"  />
              <label>(718)</label>
              <input name="RadioGroup1" type="radio" onclick="check(this.value)"  value="(212)"  />
              <label>(212)</label>
              <input name="RadioGroup1" type="radio" onclick="check(this.value)"  value="(917)"  />
              <label>(917)</label></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Apt date:</td>
            <td><input type="date" name="Apt_date" value="<?php echo date("Y-m-d"); ?>" size="20" />
              <a href="#" onclick="cal.select(document.forms[0].Apt_date,'anchor2','yyyy-MM-dd'); return false;" name="anchor2" id="anchor2">select</a></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">SalesNo:</td>
            <td><select name="LookupSalesman" id="LookupSalesman">
                <option value="" <?php if (!(strcmp("", $row_fmLeads['SalesNo']))) {echo "selected=\"selected\"";} ?>>Select from menu</option>
                <?php do { ?>
                <option value="<?php echo $row_fmSalesman['SalesNo']?>"<?php if (!(strcmp($row_fmSalesman['SalesNo'], $_GET['SalesNo']))) {echo "selected=\"selected\"";} ?>><?php echo $row_fmSalesman['Salesman']?></option>
                <?php
} while ($row_fmSalesman = mysql_fetch_assoc($fmSalesman));
$rows = mysql_num_rows($fmSalesman);
if($rows > 0) {
mysql_data_seek($fmSalesman, 0);
$row_fmSalesman = mysql_fetch_assoc($fmSalesman); } ?>
              </select></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">JobNo:</td>
            <td><select name="LookupJobNo" id="LookupJobNo">
                <option value="" <?php if (!(strcmp("", $row_fmLeads['JobNo']))) {echo "selected=\"selected\"";} ?>>Select from menu</option>
                <?php do { ?>
                <option value="<?php echo $row_fmJob['JobNo']?>"<?php if (!(strcmp($row_fmJob['JobNo'], $_GET['JobNo']))) {echo "selected=\"selected\"";} ?>><?php echo $row_fmJob['Description']?></option>
                <?php
} while ($row_fmJob = mysql_fetch_assoc($fmJob));
$rows = mysql_num_rows($fmJob);
if($rows > 0) {
mysql_data_seek($fmJob, 0);
$row_fmJob = mysql_fetch_assoc($fmJob); } ?>
              </select></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Amount:</td>
            <td><input type="text" name="Amount" value="0.00" size="20" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">AdNo:</td>
            <td><select name="LookupAdNo" id="LookupAdNo">
                <option value="" <?php if (!(strcmp("", $row_fmLeads['AdNo']))) {echo "selected=\"selected\"";} ?>>Select from menu</option>
                <?php do { ?>
                <option value="<?php echo $row_fmAdveriser['AdNo']?>"<?php if (!(strcmp($row_fmAdveriser['AdNo'], $_GET['AdNo']))) {echo "selected=\"selected\"";} ?>><?php echo $row_fmAdveriser['Advertiser']?></option>
                <?php
} while ($row_fmAdveriser = mysql_fetch_assoc($fmAdveriser));
$rows = mysql_num_rows($fmAdveriser);
if($rows > 0) {
mysql_data_seek($fmAdveriser, 0);
$row_fmAdveriser = mysql_fetch_assoc($fmAdveriser); } ?>
              </select></td>
          </tr>
        </table>
        <!---------------------------------table 3 start-->
        <table width="33%" border="0" align="right">
          <tr valign="baseline">
            <td><textarea name="Comments" id="Comments" placeholder="Enter Comment" cols="30" rows="15"></textarea></td>
          </tr>
        </table>
        <!------------------------------------table 3 end-->
      </fieldset>
      <fieldset id="fieldcolor">
        <legend id="legendcolor">Additional Info</legend>
        <table width="100%" align="left">
          <tr valign="baseline">
            <td width="11%" align="right" nowrap="nowrap">Active:</td>
            <td width="40%"><input <?php if (!(strcmp($row_fmLeads['Active'],1))) {echo "checked=\"checked\"";} ?> name="Active" type="checkbox" id="Active" value="1" checked="checked" /></td>
            <td width="13%" align="right">Call Back:</td>
            <td width="36%"><select name="CallBack" id="CallBack">
                <option value="None" <?php if (!(strcmp("None", $row_fmLeads['Call Back']))) {echo "selected=\"selected\"";} ?>>Select from menu</option>
                <option value="Sold by " <?php if (!(strcmp("Sold by ", $row_fmLeads['Call Back']))) {echo "selected=\"selected\"";} ?>>Sold</option>
                <option value="Canceled by" <?php if (!(strcmp("Canceled by", $row_fmLeads['Call Back']))) {echo "selected=\"selected\"";} ?>>Canceled </option>
                <option value="Dead by" <?php if (!(strcmp("Dead by", $row_fmLeads['Call Back']))) {echo "selected=\"selected\"";} ?>>Dead</option>
                <option value="Bought Already by" <?php if (!(strcmp("Bought Already by", $row_fmLeads['Call Back']))) {echo "selected=\"selected\"";} ?>>Bought Already</option>
                <option value="Future Work by" <?php if (!(strcmp("Future Work by", $row_fmLeads['Call Back']))) {echo "selected=\"selected\"";} ?>>Future Work</option>
                <option value="Looks Good by" <?php if (!(strcmp("Looks Good by", $row_fmLeads['Call Back']))) {echo "selected=\"selected\"";} ?>>Looks Good</option>
              </select></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Email:</td>
            <td><input type="email" name="Email" placeholder="valid email address" value="" size="32" /></td>
            <td align="right">Spouse:</td>
            <td><input type="text" name="Spouse" placeholder="spouse name" value="" size="20" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Time:</td>
            <td><input type="text" name="Time" value="<?php echo time(); ?>" size="20" /></td>
            <td align="right">:</td>
            <td></td>
          </tr>
            </tr>

        </table>
        <p>&nbsp;</p>
      </fieldset>
      <table align="center">
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">&nbsp;</td>
          <td><input name="Insert Record" type="submit" id="Insert Record" value="Insert record" />
            <input type="button" name="cancel" id="cancel" value="Cancel" onclick="history.back()" /></td>
        </tr>
      </table>
      <input type="hidden" name="LeadNo" />
      <input type="hidden" name="MM_insert" value="form1" />
    </form>
    <!-- end #mainContent --></aside>
  <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
  <footer id="footer">
    <p>New Leads</p>
    <!-- end #footer --></footer>
  <!-- end #container --></div>
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
//-->
</script>
</body>
</html>
<?php
mysql_free_result($fmLeads);

mysql_free_result($fmSalesman);

mysql_free_result($fmAdveriser);

mysql_free_result($fmJob);

mysql_free_result($fmCity);
?>

Edited by lotpb

0

Tip - separate your html and php. I like to keep functions and other php processing code in separate files and just include them when required. Echo out data where needed in the html.

You may find templating engines work well for this (e.g. twig, rainTPL, Smarty).

0

This one is pretty hard to debug since I do not have all the tables and the corresponding data. But one thing is quite obvious. On line 266 you define an input (text) box with a value taken from a $_SESSION['form'] variable:

<input type="text" name="Last_Name" id="Last_Name" autofocus value="<?php echo $_SESSION['form']; ?>" placeholder="last name" size="32" />

The thing is $_SESSION['form'] is not set before the user presses submit and is an array once the user presses submit. So in both cases it can not be echoed as a string. You should do it at least this way:

<input type="text" name="Last_Name" id="Last_Name" autofocus value="<?php echo isset($_SESSION['form']['Last_Name']) ? $_SESSION['form']['Last_Name'] : ''; ?>" placeholder="last name" size="32" />

So if we just look at the php code bit:

<?php echo isset($_SESSION['form']['Last_Name']) ? $_SESSION['form']['Last_Name'] : ''; ?>

This will echo the value of $_SESSION['form']['Last_Name'] if it is set (it exists) or empty string if the value does not exist. This is ternary way of doing it and is the same as:

<?php if(isset($_SESSION['form']['Last_Name'])) {
    echo $_SESSION['form']['Last_Name'];
} else {
    echo '';
}
?>

Hope it helps.

0

it still don't work...When i click <a href="ZipLookup.php">select</a> too Lookup....last name field still returns blank...could it be when i do the lookup i'm not summiting data????

if(!isset($_SESSION)) {
  session_start();
}
$_SESSION['form'] = $_POST;

<input type="text" name="Last_Name" id="Last_Name" autofocus value="<?php echo isset($_SESSION['form']['Last_Name']) ? $_SESSION['form']['Last_Name'] : ''; ?>" placeholder="last name" size="32" />
0

When you click this link you are not submitting the form (which uses POST). You should use submit button for that.

In your first version of code your link was:

<a href="ZipLookup.php?Last Name=<?php echo $Last_Name ?>

which still does not post the form data but would carry over the Last name usin GET method and storing it into $_GET (the $_POST is still not set). The trouble is that in the URL you can't/shouldn't have spaces. You should encode them like this:

<a href="ZipLookup.php?Last+Name=<?php echo $Last_Name ?>

or even better, change the Last Name parameter to Last_Name, like this:

<a href="ZipLookup.php?Last_Name=<?php echo $Last_Name ?>

Edited by broj1

0

Some strange reason i fill the Last_Name field then do a lookup....<a href="ZipLookup.php?Last_Name=<?php echo $Last_Name ?> $Last_Name is still blank when i go to the ZipLookup.php page...?????

0

Edit: disregard this please, I saw in your last post that you did.

Have you changed this line:

<input type="text" name="Last_Name" id="Last_Name" autofocus value="<?php echo $_SESSION['form']; ?>" placeholder="last name" size="32" />

to:

<input type="text" name="Last_Name" id="Last_Name" autofocus value="<?php echo $_SESSION['form'][Last_Name]; ?>" placeholder="last name" size="32" />

Edited by broj1

0

On the ZipLookup.php put this code in the beginning:

die($_GET['Last_Name']);

It should display last name. If not we still have an error somewhere.

0

The rest of page is blank.

Yes, die statements displays the value of $_GET and stops the execution. That's the way I prefer to debug. Prease remove the die statement.

By the way where does the $Last_Name come from (where is it being assigned a value)? You could try it this way:

<a href="ZipLookup.php?Last Name=<?php echo $_SESSION['form']['Last_Name']; ?>">select</a>

And I also noticed that in this statement the semicolon is missing at the end. Try to correct that too, please:

<a href="ZipLookup.php?Last Name=<?php echo $Last_Name'; ?>">select</a>

P.S. I have to admit that I am more or less guessing here since I don't understand the purpose completely.

0

$Last_Name come from here <input type="text" name="Last_Name" id="Last_Name" autofocus value="<?php echo $_SESSION['form'][Last_Name]; ?>" placeholder="last name" size="32" />...maybe that the problem, it's not being assigned????

0

Sory for late answer, I was away whole day.

I can't se it assigned anywhere. So try to use $_SESSION['form'][Last_Name] instead of $Last_Name.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.