Solved

save values and show it back on the form

Posted on 2008-10-08
16
178 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
  • 6
  • 4
  • 3
  • +1
16 Comments
 
LVL 17

Expert Comment

by:nanharbison
Comment Utility
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
Comment Utility
oops, take out the @ from in front of mysql_query("
0
 
LVL 3

Expert Comment

by:DerkArts
Comment Utility
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
 
LVL 9

Author Comment

by:syedasimmeesaq
Comment Utility
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
Comment Utility
DerkArts
I already tried it but if validation fails, it loses the data in the fields.
0
 
LVL 9

Author Comment

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

Expert Comment

by:DerkArts
Comment Utility
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
Comment Utility
like I said I tried that but its not working
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 17

Expert Comment

by:nanharbison
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you! That worked perfect
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
>>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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now