Page 1 of 1

Input value disappeared.

Posted: Tue Apr 17, 2007 5:51 pm
by quadoc
I've a script that has an input called "subject" and two dynamic drop down boxes one drop down is called "department" and the other drop down is called "lst_ategories", I input a value for the subject and then choose a department, some how the value of the Subject got wiped out. Could someone give me some ideas why it's doing that. Please see my code below. Thanks... :(

Code: Select all

<?php


?>
<SCRIPT LANGUAGE=javascript>

function selDept(obj)
{
   document.getElementById("hidDept").value=obj.options[obj.options.selectedIndex].value

   if(document.getElementById("hidDept").value!="")
   {					
      document.getElementById ("frmDept").submit()
   } 
}

function setFocus2(chosen)
{

   document.frmTicket.message.focus();

}


var formInUse = false;

function setFocus()
{
 if(!formInUse) {

  document.frmTicket.subject.focus();
 }
}


</SCRIPT>

<body onload="setFocus()">

<form name="frmDept" id="frmDept" method="post" action="">
<input type="hidden" name="hidDept" id="hidDept" value="<?php echo $tmpDept; ?>">
</form>

<form name="frmTicket" method="post" enctype="multipart/form-data">

       
<tr align="left" valign="bottom"> 
      <td width="130"><b><br><font color="#<?php echo $fontsubject ?>">Subject</font></b></td>
      <td><input name="subject" type="text" size="100" id="subject" value="<?php if(isset($_SESSION["subject"])){ echo $_SESSION["subject"]; } ?>">&nbsp;&nbsp;*</td>
    </tr>
    <tr align="left" valign="center"> 
      <td><br><font color="#<? echo $fontdep ?>">Department</font></td>
      <td><br>
	  <select name="department" id="department" onchange="javascript:selDept(this)">
    
 <?php

	$str =  "select * from tbl_departments ";	
	$res = mssql_query($str) or die(mssql_error());

?>

	<?

		while($data = mssql_fetch_array($res))
		{												
			  $tmp_dept = $data["department"];
			?>
               <option value = "<?=$data['id']?>" <?=(isset($_POST['department']) && $_POST['department'] == $data['id'] ? "selected=\"selected\"" : "");?>><?=$tmp_dept?>        
			   </option>
			<?php
		}
	?>
</select></td>

    </tr>   
	<tr align="left" valign="center"> 
      <td width="130"><font color="#<? echo $fontcategories ?>">Problem/Request Type</font></td>
      <td width="600"> 
	<?php

    if ($tmpDept <= 0) {$tmpDept = 1;}

    $str = "select * from tbl_categories WHERE dept_id =".$tmpDept." order by categories";

		$res = mssql_query($str) or die(mssql_error());		
	?>
		<select name = "lst_categories" id="lst_categories" onchange="javascript:setFocus2(this)">
		<option value = "">[Select One]</option>
	<?

      $clr_flag = 0;
			while($data = mssql_fetch_array($res))
			{
              if ($clr_flag == 1) {$clr = "white"; $clr_flag=0;}
              else {$clr = "mar"; $clr_flag=1;}
         
				$i_id = $data["id"];
				$s_categ = $data["categories"];
	?>

        <option value = "<?=$s_categ?>" class = "<?echo $clr;?>">
				<?=$s_categ?>
				</option>
			<?
			}
		?>
		</select>&nbsp;&nbsp;*
	  </td>
    </tr>   
<br>

</form>
</body>

Posted: Tue Apr 17, 2007 6:28 pm
by RobertGonzalez
I don't see a categories select element or a Department select element anywhere in that code (and try to stop using short tags in your code).

Posted: Tue Apr 17, 2007 6:51 pm
by quadoc
I'm sorry, I must have left it out when I cut and paste the code. I just added. The drop down lists are called "department" and "lst_categories". Thanks...

Posted: Tue Apr 17, 2007 7:06 pm
by RobertGonzalez
Before we get too into this, run the following in a new file and tell us the results please. I think it might something I have already mentioned, but I want to be sure:

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$flags['Config file'] = get_cfg_var('cfg_file_path');
if (empty($flags['Config file']))
{
	$flags['Config file'] = '-';
}
$cli = (php_sapi_name() == 'cli');
$eol = "
";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$ec = array(
	'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
	'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
	'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
	'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
	if (($t & $v) == $v)
	{
		$e[] = $n;
		$t ^= $v;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>

Posted: Wed Apr 18, 2007 10:16 am
by quadoc
Here is what it came back with.

PHP Version: 5.2.1
PHP OS: WINNT
Error Reporting: 6143 (E_ALL)
Register Globals: Off
Short Tags: On
Display Errors: Off
Magic Quotes GPC: Off
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Config file: C:\PHP\php.ini
Loaded Extensions:
bcmath calendar com_dotnet ctype
session filter ftp hash
iconv json odbc pcre
Reflection date libxml standard
tokenizer zlib SimpleXML dom
SPL wddx xml xmlreader
xmlwriter ISAPI ldap mssql
zip

Posted: Wed Apr 18, 2007 10:21 am
by RobertGonzalez
Subject appears to be a session var. Are you calling session_start() at the beginning of the script?

Posted: Wed Apr 18, 2007 10:26 am
by quadoc
yes, I do have session_start().

Posted: Wed Apr 18, 2007 10:35 am
by RobertGonzalez
Can you show the part of the code that sets the SESSION['subject'] variable?

Posted: Wed Apr 18, 2007 10:37 am
by quadoc

Code: Select all

// user index.php
 ob_start();
 include("config.php");

MSSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE FAILED TO RESPOND."); 
mssql_select_db($dbName) or DIE("Table unavailable");

/* $connection = mssql_connect($hostname, $sqlname, $sqlpass) or die("Couldn't select database.");
 $db = mssql_select_db($mssqldb, $connection) or die("Couldn't select database.");
 */
 
 session_start();

Posted: Wed Apr 18, 2007 10:41 am
by RobertGonzalez
Everah wrote:Can you show the part of the code that sets the SESSION['subject'] variable?
I mean the part where the actual variable $_SESSION['subject'] is assigned a value. And why are you using output buffering?

Posted: Wed Apr 18, 2007 11:05 am
by quadoc

Code: Select all

$subsubject = (isSet($_POST['subject'])) ? $_POST['subject'] : null;
  
if ($i_hidDept!="")
  {
    $tmpDept=$_POST["hidDept"];
  }
else {$tmpDept=1;}

	if($subsubject == ""){
		$error = 1;
		$fontsubject = "FF0000";
	} else {
		$_SESSION["subject"] = $subsubject;
	}
	
	if($subcategories == ""){
		$error = 1;
		$fontcategories = "FF0000";
	} else {
		$_SESSION["lst_categories"] = $subcategories;
	}

Posted: Wed Apr 18, 2007 11:13 am
by RobertGonzalez
So my next question is, are you sure all of those conditionals are met? At the moment, the only way that session var gets set is if there was a post var passed with the name subject that was not an empty string.

You may want to consider using some print_r() or var_dump() routines at various points along the way just to show you what is set in the $_SESSION array.

Posted: Wed Apr 18, 2007 1:28 pm
by quadoc
I have two forms in the scripts, does the session work for both forms or only on the form being submitted?

Posted: Wed Apr 18, 2007 1:50 pm
by RobertGonzalez
If a form is not submitted then data is not being passed, if that is what you are asking.

Posted: Thu Apr 19, 2007 2:23 pm
by quadoc
Ok, I figured it out what was happening. The javascript code that submit the frmDept didn't stored the session subject. I've to create some hidden fields in the frmDept to accomodate that. Thanks...