Solved

save values and show it back on the form

Posted on 2008-10-08
16
183 Views
Last Modified: 2013-12-13
I have this form below and the form works fine. But if there is any error, the data the staff enters vanishes. How can I show them the error (which I am right now) but keep what they have entered.
Thanks
<?php
// make sure the user is authenticated
@session_start();
if ((isset($_SESSION['user'])) && (isset($_SESSION['pass'])))
{
	require_once('connect_info.php');
	$result = @mysql_query("
	SELECT username, userpassword 
	FROM users 
	WHERE username='".mysql_real_escape_string($_SESSION['user'])."' 
	AND userpassword='".mysql_real_escape_string($_SESSION['pass'])."' 
	AND userlevel=1");
 
// if a record was not found, which means the user is not authenticated
if (@mysql_num_rows($result) == 0) 
{
	header("location: ../index.php");
}
	
}
else // else, the user is not authenticated
{
	header("location: ../index.php");
}
 
 
 
// default vars
$m_a = '';
$d = '';
$a_v_d = '';
$a = '';
$nc = '';
$cr = '';
$m_as = '';
$message = '';
 
if (isset($_POST['submit']))
{
    $m_a = $_POST['m_a'];
	$d = $_POST['d'];
	$a_v_d = $_POST['a_v_d'];
	$a = $_POST['areatext'];
	$nc = $_POST['nc'];
	$cr = $_POST['cr']; 
	$adminuser = $_SESSION['user'];
	$caseno = $_POST['caseno'];
	$FinalDate = $_POST['FinalDate'];
        
        
                $message = "";
        
    if (empty($m_a)) { $message .= '<font color=red>*Error 1<br></font>'; }
	if (empty($d)) { $message .= '<font color=red>*Error 2<br></font>'; }
	if (empty($a_v_d)) { $message .= '<font color=red>*Error 3<br></font>'; }
	if (empty($a)) { $message .= '<font color=red>*Error 4<br></font>'; }
	if (empty($nc)) { $message .= '<font color=red>*Error 5<br></font>'; }
	if (empty($cr)) { $message .= '<font color=red>*Error 6<br></font><br>'; }
        
        if(empty($message)) {
		session_start();
		$_SESSION['setd'] = $d;
                        
                        $result = @mysql_query("
	INSERT INTO compform
	(
		d, 
		a_v_d, 
		mas, 
		nc,
		cr, 
		user,
		area,
		caseno,
		FinalDate
	) 
	VALUES 
	(
		'".mysql_real_escape_string($d)."', 
		'".mysql_real_escape_string($a_v_d)."', 
		'".mysql_real_escape_string($m_a)."', 
		'".mysql_real_escape_string($nc)."',
		'".mysql_real_escape_string($cr)."',  
		'".mysql_real_escape_string($adminuser)."',
		'".mysql_real_escape_string($a)."',
		'".mysql_real_escape_string($caseno)."',
		'".mysql_real_escape_string($FinalDate)."'
	)") or die(mysql_error());
  		$id = mysql_insert_id();
        }
        
        if ($result && empty($message)) // if the query was successfull
        {
		
        $message .= "Successfully inserted new record<br> <a href=\"../../../../form2.php?idre=$id\" target=\"_blank\"></a>";
		
		
		
		
		$m_a = '';
		$d = '';
		$a_v_d = '';
		$nc = '';
		$cr = '';
		$m_as = '';
                
 
        }
        else // else if the query was not successfull
        {
               $message .= '*Error New<br>';
				
        }
       	
 @session_start();
$_SESSION["msg"]  = $message;
header("Location: " . $_SERVER['PHP_SELF']);
exit();
 
        
}
 else {
 
@session_start();
if(isset($_SESSION["msg"]))
{
   $message = $_SESSION['msg'];
   $_SESSION['msg'] = ''; // reset the message after using it
}
else
{
   $message="";
}
 
}
// create a drop down box code in an appendable php variable
$m_as = '<select name="m_a">';
$m_as .= '<option value="">-Select-</option>';
 
// query the database and return a list of options for the select box
$result = @mysql_query("SELECT mid, mas FROM m_as_c");
// check to see if a result was returned - this is good error prevention
if (@mysql_num_rows($result) > 0)
{
	// now, loop through the result set and build the html options tags
	while($nt = mysql_fetch_array($result))
	{
		if ($monitoring_area == $nt['mid'])
		{
			$m_as .= '<option value="'.$nt['mas'].'" selected>"'.$nt['mas'].'"</option>';
		}
		else
		{
			$m_as .= '<option value="'.$nt['mas'].'">"'.$nt['mas'].'"</option>';
		}
	}
}
else // else if the above query fails, then display it as an option
{
	$m_as .= '<option value="">No Options Available</option>';
}
 
 
?>
<html>
<head>
<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
</head>
<body>
<style type="text/css">
<!--
.txtBlack14 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
}
-->
</style>
 
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table width="654" border="0">
  <tr>
    <td width="233" class="txtBlack14">User: &nbsp;&nbsp;<b><?php echo $_SESSION['user']; ?></b><br><br></td>
    <td width="1" class="txtBlack14">&nbsp;</td>
    <td class="txtBlack14">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" class="txtBlack14"><center><?php echo $message; ?>&nbsp;</td>
    </tr>
  <tr>
    <td colspan="2">D:</td>
    <td><select name="d" id="d">
          <option>2001</option>
          <option>2002</option>
          
    </select></td>
  </tr>
  <tr>
    <td colspan="2">CNo:</td>
    <td><input name="cno" type="text" id="cno" size="32" value="<?php echo  strval($_REQUEST['cno']);  ?>"></td>
  </tr>
  
  <tr> 
    <td colspan="2"></td>
    <td><?php echo $m_as; ?>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td rowspan="3"><textarea name="nc" id="nc" cols="55" rows="4"><?php echo $nc; ?></textarea></td>
  </tr>
  <tr>
    <td colspan="2"></td>
    </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td rowspan="3"><textarea name="cr" id="cr" cols="55" rows="4"><?php echo $cr; ?></textarea></td>
  </tr>
  <tr>
    <td colspan="2"> </td>
    </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
  <tr>
    <td colspan="2"></td>
    <td width="406"><input name="areatext" type="text" id="atext" size="32"></td>
  </tr>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td><input type="submit" name="submit" id="submit1" value="Submit"/></td>
  </tr>
</table>
</form>
</body>
</html>

Open in new window

0
Comment
Question by:syedasimmeesaq
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +1
16 Comments
 
LVL 17

Expert Comment

by:nanharbison
ID: 22673666
The first thing that is wrong here is that you don't have the session start at the very top of the code
change this:
<?php
// make sure the user is authenticated
@session_start();

to this:
<?php
session_start();
// make sure the user is authenticated

but then you have session start later on in the code. It has to be at the top of the page.

The second thing is that putting the @ in front of a PHP function suppresses errors, so you are not seeing them. Trying removing that.

Then add the code to show errors at the end of your $result, see below.

        $result = @mysql_query("
        SELECT username, userpassword 
        FROM users 
        WHERE username='".mysql_real_escape_string($_SESSION['user'])."' 
        AND userpassword='".mysql_real_escape_string($_SESSION['pass'])."' 
        AND userlevel=1")or die('Query failed: ' . mysql_error());

Open in new window

0
 
LVL 17

Expert Comment

by:nanharbison
ID: 22673673
oops, take out the @ from in front of mysql_query("
0
 
LVL 3

Expert Comment

by:DerkArts
ID: 22673704
The easiest solution, but not the most beautifull, is this:

Fill every form value with $_POST values, like this:
<textarea name="nc" id="nc" cols="55" rows="4"><?php echo $_POST['nc'] ?></textarea>

Then, when you load your datafrom the database, set this data in the $_POST array. Like this.
$_POST['nc'] = $nc;

So the first time the page is loaded, $_POST will be filled with data from the database, the second time (when there is an error), it will be filled with data the user submitted, making sure all the forms are always filled.

Quick n dirty :) But no real disadvantages really. Just esthetics.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 22673712
I am not sure why session is important here. I was thinking of using strval($_Request) to keep the values after the validation so they still show in the form.
0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 22673731
DerkArts
I already tried it but if validation fails, it loses the data in the fields.
0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 22673790
nanharbison: I think I confused you. Its not the mysql error . Its the validation error.
Thanks
0
 
LVL 3

Expert Comment

by:DerkArts
ID: 22673889
syedasimmeesaq:
That would be very strange, as $_POST cannot lose its values unless the page is refreshed or redirected.

You have to make sure you dont overwrite the $_POST values when validation goes wrong. I'll post a very short example. I hope you understand the flow
if(!isset($_POST)){
 $res = mysql_query("SELECT.........");
 $arr = mysql_fetch_assoc(res);
 $_POST = $arr;
}else{
  $boolValid = validate($_POST);
  if($boolValid){
      saveEverythingToDb($_POST);
       $msg  = "Data saved!!";
  }else{
    $msg = "There was an error";
  }
}
 
?>
<h2><?=@$msg?></h2>
<form>
 <input type='text' value='<?=$_POST['fieldname']?>' name='fieldname'>
</form>

Open in new window

0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 22674101
like I said I tried that but its not working
0
 
LVL 17

Expert Comment

by:nanharbison
ID: 22674525
the post values are being unset by these lines:
            $m_a = '';
            $d = '';
            $a_v_d = '';
            $nc = '';
            $cr = '';
            $m_as = '';

somehow this if statement is not working:
if ($result && empty($message)) // if the query was successfull

so then when you try to fill a textbox like this:
<?php echo $nc; ?>
it is not being filled.

you should try echoing values, like echo the query and echo the post values, and add an echo after the above if statement to see why the variable are being unset. That way you can see what is going wrong.

Also, have you removed all of the session_start() calls after the first one? You only need the first one.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22675470
you need to initialize your variables BEFORE the
if (isset($_POST['submit']))
<?php
// make sure the user is authenticated
@session_start();
if ((isset($_SESSION['user'])) && (isset($_SESSION['pass'])))
{
	require_once('connect_info.php');
	$result = @mysql_query("
	SELECT username, userpassword 
	FROM users 
	WHERE username='".mysql_real_escape_string($_SESSION['user'])."' 
	AND userpassword='".mysql_real_escape_string($_SESSION['pass'])."' 
	AND userlevel=1");
 
	// if a record was not found, which means the user is not authenticated
	if (@mysql_num_rows($result) == 0) 
	{
		header("location: ../index.php");
		exit;
	}	
}
else // else, the user is not authenticated
{
	header("location: ../index.php");
	exit;
}
 
// default vars
 
$m_as = '';
$message = '';
 
$m_a = (isset($_POST['m_a']) ? $_POST['m_a']:'');
$cno = (isset($_POST['cno']) ? $_POST['cno']:'');
$a_v_d = (isset($_POST['a_v_d']) ? $_POST['a_v_d']:'');
$a = (isset($_POST['areatext']) ? $_POST['areatext']:'');
$nc = (isset($_POST['nc']) ? $_POST['nc']:'');
$cr = (isset($_POST['cr']) ? $_POST['cr']:'');
$adminuser = (isset($_SESSION['user']) ? $_SESSION['user']:'');
$caseno = (isset($_POST['caseno']) ? $_POST['caseno']:'');
$FinalDate = (isset($_POST['FinalDate']) ? $_POST['FinalDate']:'');
 
//maintain state on dates dropdown list
$d = (isset($_POST['d']) ? $_POST['d']:'');
$dates=array("","");
switch(strval($d))
{
	case "2001":$dates[0]=" selected='selected' ";break;
	case "2002":$dates[1]=" selected='selected' ";break;
}
 
if (isset($_POST['submit']))
{
	$message = "";
        
    	if (empty($m_a)) { $message .= '<font color=red>*Error 1<br></font>'; }
	if (empty($d)) { $message .= '<font color=red>*Error 2<br></font>'; }
	if (empty($a_v_d)) { $message .= '<font color=red>*Error 3<br></font>'; }
	if (empty($a)) { $message .= '<font color=red>*Error 4<br></font>'; }
	if (empty($nc)) { $message .= '<font color=red>*Error 5<br></font>'; }
	if (empty($cr)) { $message .= '<font color=red>*Error 6<br></font><br>'; }
	if(empty($message)) 
	{
		//session_start();
		$_SESSION['setd'] = $d;              
          $result = @mysql_query("
		INSERT INTO compform
		(
			d, 
			a_v_d, 
			mas, 
			nc,
			cr, 
			user,
			area,
			caseno,
			FinalDate
		) 
		VALUES 
		(
			'".mysql_real_escape_string($d)."', 
			'".mysql_real_escape_string($a_v_d)."', 
			'".mysql_real_escape_string($m_a)."', 
			'".mysql_real_escape_string($nc)."',
			'".mysql_real_escape_string($cr)."',  
			'".mysql_real_escape_string($adminuser)."',
			'".mysql_real_escape_string($a)."',
			'".mysql_real_escape_string($caseno)."',
			'".mysql_real_escape_string($FinalDate)."'
		)") or die(mysql_error());
  		$id = mysql_insert_id();
     }
        
     if ($result && empty($message)) // if the query was successfull
     {
		
		$message .= "Successfully inserted new record<br> <a href=\"../../../../form2.php?idre=$id\" target=\"_blank\"></a>";
		$m_a = '';
		$d = '';
		$a_v_d = '';
		$nc = '';
		$cr = '';
		$m_as = '';
     }
     else // else if the query was not successfull
     {
		$message .= '*Error New<br>';
    	}
	//@session_start();
	$_SESSION["msg"]  = $message;
	header("Location: " . $_SERVER['PHP_SELF']);
	exit();
}
else
{
	//@session_start();
	if(isset($_SESSION["msg"]))
	{
		$message = $_SESSION['msg'];
		$_SESSION['msg'] = ''; // reset the message after using it
	}
	else
	{
		$message="";
	} 
}
 
// create a drop down box code in an appendable php variable
$m_as = '<select name="m_a">';
$m_as .= '<option value="">-Select-</option>';
 
// query the database and return a list of options for the select box
$result = @mysql_query("SELECT mid, mas FROM m_as_c");
// check to see if a result was returned - this is good error prevention
if (@mysql_num_rows($result) > 0)
{
	// now, loop through the result set and build the html options tags
	while($nt = mysql_fetch_array($result))
	{
		if ($monitoring_area == $nt['mid'])
		{
			$m_as .= '<option value="'.$nt['mas'].'" selected>"'.$nt['mas'].'"</option>';
		}
		else
		{
			$m_as .= '<option value="'.$nt['mas'].'">"'.$nt['mas'].'"</option>';
		}
	}
}
else // else if the above query fails, then display it as an option
{
	$m_as .= '<option value="">No Options Available</option>';
} 
?>
<html>
<head>
<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
</head>
<body>
<style type="text/css">
<!--
.txtBlack14 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
}
-->
</style>
 
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table width="654" border="0">
  <tr>
    <td width="233" class="txtBlack14">User: &nbsp;&nbsp;<b><?php echo $_SESSION['user']; ?></b><br><br></td>
    <td width="1" class="txtBlack14">&nbsp;</td>
    <td class="txtBlack14">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" class="txtBlack14"><center><?php echo $message; ?>&nbsp;</td>
    </tr>
  <tr>
    <td colspan="2">D:</td>
    <td><select name="d" id="d">
          <option <?php echo $dates[0]; ?> value="2001">2001</option>
          <option <?php echo $dates[1]; ?> value="2002">2002</option>
          
    </select></td>
  </tr>
  <tr>
    <td colspan="2">CNo:</td>
    <td><input name="cno" type="text" id="cno" size="32" value="<?php echo  $cno;  ?>"></td>
  </tr>
  
  <tr> 
    <td colspan="2"></td>
    <td><?php echo $m_as; ?>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td rowspan="3"><textarea name="nc" id="nc" cols="55" rows="4"><?php echo $nc; ?></textarea></td>
  </tr>
  <tr>
    <td colspan="2"></td>
    </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td rowspan="3"><textarea name="cr" id="cr" cols="55" rows="4"><?php echo $cr; ?></textarea></td>
  </tr>
  <tr>
    <td colspan="2"> </td>
    </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
  <tr>
    <td colspan="2"></td>
    <td width="406"><input name="areatext" type="text" id="atext" value="<?php echo $a; ?>" size="32"></td>
  </tr>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td><input type="submit" name="submit" id="submit1" value="Submit"/></td>
  </tr>
</table>
</form>
</body>
</html>

Open in new window

0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 22680224
Heilo I did what you suggested and when I click submit andI leave a field blank , it shows me the error but then it still blanks out all my fields.
Thanks
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22680432
save as test.php and try it:
<?php
// make sure the user is authenticated
@session_start();
if ((isset($_SESSION['user'])) && (isset($_SESSION['pass'])))
{
	require_once('connect_info.php');
	$result = @mysql_query("
	SELECT username, userpassword 
	FROM users 
	WHERE username='".mysql_real_escape_string($_SESSION['user'])."' 
	AND userpassword='".mysql_real_escape_string($_SESSION['pass'])."' 
	AND userlevel=1");
 
	// if a record was not found, which means the user is not authenticated
	if (@mysql_num_rows($result) == 0) 
	{
		header("location: ../index.php");
		exit;
	}	
}
else // else, the user is not authenticated
{
	header("location: ../index.php");
	exit;
}
 
// default vars
 
$m_as = '';
$message = '';
 
$m_a = (isset($_POST['m_a']) ? $_POST['m_a']:'');
$cno = (isset($_POST['cno']) ? $_POST['cno']:'');
$a_v_d = (isset($_POST['a_v_d']) ? $_POST['a_v_d']:'');
$a = (isset($_POST['areatext']) ? $_POST['areatext']:'');
$nc = (isset($_POST['nc']) ? $_POST['nc']:'');
$cr = (isset($_POST['cr']) ? $_POST['cr']:'');
$adminuser = (isset($_SESSION['user']) ? $_SESSION['user']:'');
$caseno = (isset($_POST['caseno']) ? $_POST['caseno']:'');
$FinalDate = (isset($_POST['FinalDate']) ? $_POST['FinalDate']:'');
 
//maintain state on dates dropdown list
$d = (isset($_POST['d']) ? $_POST['d']:'');
$dates=array("","");
switch(strval($d))
{
	case "2001":$dates[0]=" selected='selected' ";break;
	case "2002":$dates[1]=" selected='selected' ";break;
}
 
if (isset($_POST['submit']))
{
	$message = "";
        
    	if (empty($m_a)) { $message .= '<font color=red>*Error 1<br></font>'; }
	if (empty($d)) { $message .= '<font color=red>*Error 2<br></font>'; }
	if (empty($a_v_d)) { $message .= '<font color=red>*Error 3<br></font>'; }
	if (empty($a)) { $message .= '<font color=red>*Error 4<br></font>'; }
	if (empty($nc)) { $message .= '<font color=red>*Error 5<br></font>'; }
	if (empty($cr)) { $message .= '<font color=red>*Error 6<br></font><br>'; }
	if(empty($message)) 
	{
		//session_start();
		$_SESSION['setd'] = $d;              
          $result = @mysql_query("
		INSERT INTO compform
		(
			d, 
			a_v_d, 
			mas, 
			nc,
			cr, 
			user,
			area,
			caseno,
			FinalDate
		) 
		VALUES 
		(
			'".mysql_real_escape_string($d)."', 
			'".mysql_real_escape_string($a_v_d)."', 
			'".mysql_real_escape_string($m_a)."', 
			'".mysql_real_escape_string($nc)."',
			'".mysql_real_escape_string($cr)."',  
			'".mysql_real_escape_string($adminuser)."',
			'".mysql_real_escape_string($a)."',
			'".mysql_real_escape_string($caseno)."',
			'".mysql_real_escape_string($FinalDate)."'
		)") or die(mysql_error());
  		$id = mysql_insert_id();
        
	     if ($result && empty($message)) // if the query was successfull
	     {
		
			$message .= "Successfully inserted new record<br> <a href=\"../../../../form2.php?idre=$id\" target=\"_blank\"></a>";
			$m_a = '';
			$d = '';
			$a_v_d = '';
			$nc = '';
			$cr = '';
			$m_as = '';
 
			//@session_start();
			$_SESSION["msg"]  = $message;
			
			//you can only redirect when query succeeds. If the query fails
			//and you redirect back to PHP_SELF, then you are just starting over
			//as if though you are arriving at the page for the first time
			//so you would loose the previous values
			header("Location: " . $_SERVER['PHP_SELF']);
			exit();
	     }
	     else // else if the query was not successfull
	     {
			$message .= '*Error New<br>';
	    	}
     }
}
else
{
	//@session_start();
	if(isset($_SESSION["msg"]))
	{
		$message = $_SESSION['msg'];
		$_SESSION['msg'] = ''; // reset the message after using it
	}
	else
	{
		$message="";
	} 
}
 
// create a drop down box code in an appendable php variable
$m_as = '<select name="m_a">';
$m_as .= '<option value="">-Select-</option>';
 
// query the database and return a list of options for the select box
$result = @mysql_query("SELECT mid, mas FROM m_as_c");
// check to see if a result was returned - this is good error prevention
if (@mysql_num_rows($result) > 0)
{
	// now, loop through the result set and build the html options tags
	while($nt = mysql_fetch_array($result))
	{
		if ($monitoring_area == $nt['mid'])
		{
			$m_as .= '<option value="'.$nt['mas'].'" selected>"'.$nt['mas'].'"</option>';
		}
		else
		{
			$m_as .= '<option value="'.$nt['mas'].'">"'.$nt['mas'].'"</option>';
		}
	}
}
else // else if the above query fails, then display it as an option
{
	$m_as .= '<option value="">No Options Available</option>';
} 
?>
<html>
<head>
<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
</head>
<body>
<style type="text/css">
<!--
.txtBlack14 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
}
-->
</style>
 
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table width="654" border="0">
  <tr>
    <td width="233" class="txtBlack14">User: &nbsp;&nbsp;<b><?php echo $_SESSION['user']; ?></b><br><br></td>
    <td width="1" class="txtBlack14">&nbsp;</td>
    <td class="txtBlack14">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" class="txtBlack14"><center><?php echo $message; ?>&nbsp;</td>
    </tr>
  <tr>
    <td colspan="2">D:</td>
    <td><select name="d" id="d">
          <option <?php echo $dates[0]; ?> value="2001">2001</option>
          <option <?php echo $dates[1]; ?> value="2002">2002</option>
          
    </select></td>
  </tr>
  <tr>
    <td colspan="2">CNo:</td>
    <td><input name="cno" type="text" id="cno" size="32" value="<?php echo  $cno;  ?>"></td>
  </tr>
  
  <tr> 
    <td colspan="2"></td>
    <td><?php echo $m_as; ?>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td rowspan="3"><textarea name="nc" id="nc" cols="55" rows="4"><?php echo $nc; ?></textarea></td>
  </tr>
  <tr>
    <td colspan="2"></td>
    </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td rowspan="3"><textarea name="cr" id="cr" cols="55" rows="4"><?php echo $cr; ?></textarea></td>
  </tr>
  <tr>
    <td colspan="2"> </td>
    </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
  <tr>
    <td colspan="2"></td>
    <td width="406"><input name="areatext" type="text" id="atext" value="<?php echo $a; ?>" size="32"></td>
  </tr>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td><input type="submit" name="submit" id="submit1" value="Submit"/></td>
  </tr>
</table>
</form>
</body>
</html>

Open in new window

0
 
LVL 17

Expert Comment

by:nanharbison
ID: 22680513
On your form, I don't see a form element with name="a_v_d", but you have:
$a_v_d = (isset($_POST['a_v_d']) ? $_POST['a_v_d']:'');
which is assuming it is on the form.
You also are referring to POST variables called caseno, FInalDate which are not on the form. You need to add those to the form.


0
 
LVL 3

Expert Comment

by:DerkArts
ID: 22680685
hielo, several solutions have been posted here. If you follow the procedure like i posted it, it will work 100%.

The thing, you need to do some effort as well. If you take a good look at my example, en rewrite your code according to that, it will work for sure.
0
 
LVL 9

Author Closing Comment

by:syedasimmeesaq
ID: 31504431
Thank you! That worked perfect
0
 
LVL 82

Expert Comment

by:hielo
ID: 22684417
>>If you follow the procedure like i posted it, it will work 100%.
Not on this problem. That will work only when there is posted information. The problem with his code is that he was redirecting  back to index.php instead of letting the processing "fall-through". When you redirect, the original contents of the $_POST were being list. The fix was to redirect only when necessary NOT all the time.

>>Thank you!
you are welcome
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
migrating to phpbb forum from vBulletin 4.2 3 93
How do i use the await event in php echo 5 43
Ajax success not firing alert 6 41
Load string Array from file 23 41
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question