Jump to content

Recommended Posts

Hello, I have a funny problem. I have a long php file in which I have added a HTML form which is very simple. It has a checkbox and then submit button. I submit the form to the self (same php file) and then check if the checkbox was clicked. When checkbox was not clicked, $_POST gives me the data that submit was hit but when checkbox was clicked, I do not get any POST data. The problem is not consistent. Some times it works but mostly it does not work. I change from POST to GET and the same problem.

To isolate the problem, I just copied the poriton of the form which was creating the problem in a new file test1.php and it works perfectly. Again, now if I submit the form from my origional file "ManageMapping.php" to this test1.php, I see that POST has all the data. However, when I go back to my origional file "ManageMapping.php". it does not work. The test1.phpo which works is below

<?php
echo "<pre>";
echo "post is";
print_r($_POST);
echo "get is";
print_r($_GET);
		echo "request is";
print_r($_REQUEST);
echo "let us check HTTP_POST_VARS";
print_r($HTTP_POST_VARS);
echo "</pre>";



?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" media="all" href="../../stylesheet.css">
<title>Managing URL to StartContext Mapping </title>
</head>

<body style="margin: 0px;" onLoad="preloader();">


<form enctype="multipart/form-data" action="test1.php" method="POST">
<input type="hidden" name="submitted" value="true">

<input type="checkbox" name="dboptions" class="radio">Delete existing mappings from the database before loading the data from the CSV File.
<input type="submit" name="submit" class="buttons" value="submit">
</form> 


</body>
</html>

The origional file "ManageMapping.php" which is creating problem is

<?php
echo "<pre>";
print_r($_POST);
echo "get is";
	print_r($_GET);
		echo "request is";
	print_r($_REQUEST);
echo "let us check HTTP_POST_VARS";
print_r($HTTP_POST_VARS);
echo "</pre>";

session_start();
require('../../inc/inputcheck.php');
set_time_limit(0);


// Make sure user is logged in.
if ($_SESSION['BOTID']==""){
header('Location: http://'.$_SERVER['HTTP_HOST'].root_dir().'/index.php?kOut=true');
}
if ($_SESSION['display_mode']!=""){
$display_mode=$_SESSION['display_mode'];
	}
else
{
	$display_mode="new";
}



if ($_POST['submitted']){
echo "page submitted";
		$display_mode="submitted";
		}

echo "display_mode is".$display_mode;

$dbupdated="false";

if ($_SESSION['mapping_array']!=""){
$mapping_array=$_SESSION['mapping_array'];
}




if ($display_mode=="submitted"){
echo "Display mod is submitted. Let us update database";
$dbconnect=oci_connect($_SESSION['db_username'],$_SESSION['db_password'],$_SESSION['sid']) or die(oci_error());
if($_POST['dboptions']=="on")
{
	$query = "delete from vzn_startcontext";
	$stmt = oci_parse($dbconnect, $query);
	if (!$stmt) {
		 $e = oci_error($dbconnect);
		print htmlentities("Somethings wrong : " .$e['message']);
		exit;
		}
	$r = oci_execute($stmt,OCI_DEFAULT);	
	if (!$r) {
		$e = oci_error($stmt);
		echo "<pre>".$e['message']."</pre>\n";
		}
}

foreach($mapping_array as $mapping_array_row){
	$query = "insert into vzn_startcontext values("."'".$mapping_array_row['url']."','".$mapping_array_row['pagetitle']."',".strlen($mapping_array_row['url']).",'".$mapping_array_row['startcontext']."')";
	$stmt = oci_parse($dbconnect, $query);
	if (!$stmt) {
		 $e = oci_error($dbconnect);
		 echo "<pre>".$e['message']."</pre>\n";
		 exit;
		}
		$r = oci_execute($stmt, OCI_DEFAULT);	
	if (!$r) {
		$e = oci_error($stmt); 
		echo "<pre>".$e['message']."</pre>\n";
			}
	}

oci_commit($dbconnect);
$dbupdated=true;
$_SESSION['dbupdated']= $dbupdated;
echo "updating the database was successfull, changing the display mode to dbupdated";
$display_mode="dbupdated";
header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/ManageMapping.php');
}




?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" media="all" href="../../stylesheet.css">
<script language="JavaScript" src="../../javascript/CalendarPopup.js"></script>
<script language="JavaScript" src="../../javascript/AnchorPosition.js"></script>
<script language="JavaScript" src="../../javascript/date.js"></script>
<script language="JavaScript" src="../../javascript/PopupWindow.js"></script>
<script language="javascript">
<!--

function preloader(){
	AllImages=new Array("../../site_images/Category_on.gif", "../../site_images/Conv2_on.gif", "../../site_images/Usage_on.gif", "../../site_images/Answer_on.gif", "../../site_images/Word_on.gif", "../../site_images/Download_on.gif", "../../site_images/YHome_on.gif");
	for(loadall=0; loadall<AllImages.length; loadall++){
		var LoadedImage=new Image();
		LoadedImage.src=AllImages[loadall];
	}
}

	function overImage(imageItem){
	image = eval(document.getElementById(imageItem));
	image.src = "../../site_images/"+imageItem+"_on.gif";
}

function outImage(imageItem){
	image = eval(document.getElementById(imageItem));
	image.src = "../../site_images/"+imageItem+"_off.gif";
}
//-->
</script>
<title>Managing URL to StartContext Mapping </title>
</head>

<body style="margin: 0px;" onLoad="preloader();">
<table width="770" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td width="117" valign="top">
		<table border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td><img src="../../images/space.gif" width="1" height="50"></td>
			</tr>
			<tr>
				<td> <span class="left_title">Managing URL to StartContext Mapping </span></td>
			</tr>
			<tr>
				<td><img src="../images/space.gif" width="1" height="5"></td>
			</tr>
			<tr>
				<td><a href="category.php"><img src="../../site_images/Category_on.gif" border="0" id="Category"></a></td>
			</tr>
			<tr>
				<td><a href="conversations.php" onMouseOver="overImage('Conv2');" onMouseOut="outImage('Conv2');"><img src="../../site_images/Conv2_off.gif" border="0" id="Conv2"></a></td>
			</tr>
			<tr>
				<td><a href="usage.php" onMouseOver="overImage('Usage');" onMouseOut="outImage('Usage');"><img src="../../site_images/Usage_off.gif" border="0" id="Usage"></a></td>
			</tr>
			<tr>
				<td><a href="answerFreq.php?botid=<?php echo $BOTID; ?>" onMouseOver="overImage('Answer');" onMouseOut="outImage('Answer');"><img src="../../site_images/Answer_off.gif" border="0" id="Answer"></a></td>
			</tr>
			<tr>
				<td><a href="wordSearch.php" onMouseOver="overImage('Word');" onMouseOut="outImage('Word');"><img src="../../site_images/Word_off.gif" border="0" id="Word"></a></td>
			</tr>
			<tr>
				<td><a href="download/index.php" onMouseOver="overImage('Download');" onMouseOut="outImage('Download');"><img src="../../site_images/Download_off.gif" border="0" id="Download"></a></td>
			</tr>
			<tr>
				<td><a href="../../sign-in.php" onMouseOver="overImage('YHome');" onMouseOut="outImage('YHome');"><img src="../../site_images/YHome_off.gif" border="0" id="YHome"></a></td>
			</tr>
		</table>
	</td>
	<td width="653" align="center">

		<table> <!-- start table to represent right column -->

<!-- start of first inner table -->

		<tr>	<td align="left">
		<table><tr>	<td align="left">
	<br>
	<br>
<?php
echo "display mod is".$display_mode;
if (($display_mode=="new")||($display_mode=="readfile")){
?>

<FORM ENCTYPE="multipart/form-data" ACTION="readmappingfile.php" METHOD=POST>
<strong>URL to StartContext Mapping File : </strong><br>
The file must be in CSV format with the structure : - URL, Title, StartContext. The header row must not be present.<br>
<INPUT NAME="mapping_file" size="75" TYPE="file">
<INPUT TYPE="submit" VALUE="Read File"><br>
</FORM>
</td></tr>
</table>
</td></tr>
<!-- end  of first inner table -->

<?php
}
?>


<?php
if ($display_mode=="readfile"){
?>
<!-- start of second inner table -->
<tr>	<td align="left">
<table width="250" border="1" cellspacing="0" cellpadding="1" bordercolor="gray" align="left" >
<tr><td>URL</td><td>Title</td><td>StartContext</td></tr>

<?php
foreach($mapping_array as $mapping_array_row)
{
echo "<tr>";
foreach($mapping_array_row as $mapping_array_row_cell){
	echo "<td align=\"left\">";
	if ($mapping_array_row_cell!='')
	echo $mapping_array_row_cell;
	else
		echo "&nbsp";
	echo "</td>";
	}
echo "</tr>";
}
?>
</table>
</td></tr>
<!-- end of second inner table -->

<!-- start of third  inner table -->
<tr><td>
<table border="0" cellpadding="4" cellspacing="2" >
<tr><td>

<form enctype="multipart/form-data" action="ManageMapping.php" method="post">
<input type="hidden" name="submitted" value="true">

<table>
<!--	<tr>
	<td align="right"><input type="radio" name="dboptions" class="radio" value="replace1"></td>
	<td>Replace existing mappings in the database with the data from the CSV File.</td>
</tr>
<tr>
	<td align="right"><input type="radio" name="dboptions" class="radio" value="append"></td>
	<td>Append existing mappings in the database with the data from CSV File.</td>

<tr> -->

<tr>
	<td align="right"><input type="checkbox" name="dboptions" class="radio"></td>
	<td>Delete existing mappings from the database before loading the data from the CSV File.</td>

<tr>

	<td colspan="2" align="right">		
	<br></td>
</tr>
</table>
<input type="submit" name="submit" class="buttons" value="submit">
</form>

</td></tr></table>
</td></tr>
<!-- end of third  inner table -->


<?php
}else if ($display_mode=="dbupdated"){
if ($_SESSION['dbupdated'])
	{
		echo "The mapping into database has been successfully updated.";
	}
}
?>




		</table> <!-- end table to represent right column -->

</td></tr></table>


<form enctype="multipart/form-data" action="ManageMapping.php" method="post">
<input type="hidden" name="submitted" value="true">

<input type="checkbox" name="dboptions" class="radio">Delete existing mappings from the database before loading the data from the CSV File.
<input type="submit" name="submit" class="buttons" value="submit">
</form> 




</body>
</html>

<form enctype="multipart/form-data" action="ManageMapping.php" method="post">

<input type="hidden" name="submitted" value="true">

 

<input type="checkbox" name="dboptions" class="radio">Delete existing mappings from the database before loading the data from the CSV File.

<input type="submit" name="submit" class="buttons" value="submit">

</form

 

The only thing I can see is that you don't need enctype="multipart/form-data"

 

The enctype is used when you're uploading photos or dealing with files etc..

 

Take that out and see what happens

I tested without enctype. I replaced the origional line with <form action="ManageMapping.php" method="post">

But it does not resolve the problem. Status is same. test1.php works . ManageMapping.php is able to get the post data only if I do not select the checkbox and only hit the submit button. If I select the checkbox and hit the submit button, there is no POST data. Please advise as this is the second continuous day of troubleshooting of this silly problem.

Seeing as you have mutliple forms why not try naming your forms;

 

Even if its...

 

<form name="form1" action="ManageMapping.php" method="post">

<form name="form2" action="ManageMapping.php" method="post">

<form name="form3" action="ManageMapping.php" method="post">

I have named the form now.. The form1 is to load the CSV file and there is no issue with that. The issue is with form2. As you see form2 has checkbox and submit button. If I do not check the checkbox, I get post data as shown below which is correct.

POST isArray
(
    [submitted] => true
    [submit] => submit
)
get isArray
(
)
request isArray
(
    [submitted] => true
    [submit] => submit
    [phpSESSID] => a10vud149jt2dcgprrndei9fs4
)
HTTP_POST_VARS  is

But, if I check the checkbox and hit submit, then the POST data does not come.

POST isArray
(
)
get isArray
(
)
request isArray
(
    [phpSESSID] => a10vud149jt2dcgprrndei9fs4
)
HTTP_POST_VARS  is
display_mode isreadfile 

The same issue happens if I use GET instead of POST. or if I use radio button instead of the checkbox. Surprisingly the issue does not appear if I make a small php file as shown above as test1.php which has only form and required data.

=========

header() redirect is used only in certain cases like when the user has not logged in. I have tested those scenario and its file. The current scenario of submitting a form does not hit that part of the code which calles header redirect.

 

========

 

This is third day of me struggling with this funny issue. So, please help.

 

==

The full code for your reference is here

<?php
session_start();
require('../../inc/inputcheck.php');
set_time_limit(0);

// for debugging only
echo "<pre>";
echo "POST is";
print_r($_POST);
echo "get is";
print_r($_GET);
echo "request is";
print_r($_REQUEST);
echo "HTTP_POST_VARS  is";
print_r($HTTP_POST_VARS);
echo "</pre>";


// Make sure user is logged in.
if ($_SESSION['BOTID']==""){
header('Location: http://'.$_SERVER['HTTP_HOST'].root_dir().'/index.php?kOut=true');
}

if ($_SESSION['display_mode']!="")
{
	$display_mode=$_SESSION['display_mode'];
}
else
{
	$display_mode="new";
}


if ($_POST['submitted'])
{
		$display_mode="submitted";
}

echo "display_mode is".$display_mode;

$dbupdated="false";

if ($_SESSION['mapping_array']!="")
{
	$mapping_array=$_SESSION['mapping_array'];
}




if ($display_mode=="submitted"){
echo "Display mod is submitted. Let us update database";
$dbconnect=oci_connect($_SESSION['db_username'],$_SESSION['db_password'],$_SESSION['sid']) or die(oci_error());
if($_POST['dboptions']=="delete")
{
	$query = "delete from vzn_startcontext";
	$stmt = oci_parse($dbconnect, $query);
	if (!$stmt) {
		 $e = oci_error($dbconnect);
		print htmlentities("Somethings wrong : " .$e['message']);
		exit;
		}
	$r = oci_execute($stmt,OCI_DEFAULT);	
	if (!$r) {
		$e = oci_error($stmt);
		echo "<pre>".$e['message']."</pre>\n";
		}
}

foreach($mapping_array as $mapping_array_row){
	$query = "insert into vzn_startcontext values("."'".$mapping_array_row['url']."','".$mapping_array_row['pagetitle']."',".strlen($mapping_array_row['url']).",'".$mapping_array_row['startcontext']."')";
	$stmt = oci_parse($dbconnect, $query);
	if (!$stmt) {
		 $e = oci_error($dbconnect);
		 echo "<pre>".$e['message']."</pre>\n";
		 exit;
		}
		$r = oci_execute($stmt, OCI_DEFAULT);	
	if (!$r) {
		$e = oci_error($stmt); 
		echo "<pre>".$e['message']."</pre>\n";
			}
	}

oci_commit($dbconnect);
$dbupdated=true;
$_SESSION['dbupdated']= $dbupdated;
echo "updating the database was successfull, changing the display mode to dbupdated";
$display_mode="dbupdated";
header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/ManageMapping.php');
}




?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" media="all" href="../../stylesheet.css">
<script language="JavaScript" src="../../javascript/CalendarPopup.js"></script>
<script language="JavaScript" src="../../javascript/AnchorPosition.js"></script>
<script language="JavaScript" src="../../javascript/date.js"></script>
<script language="JavaScript" src="../../javascript/PopupWindow.js"></script>
<script language="javascript">
<!--

function preloader(){
	AllImages=new Array("../../site_images/Category_on.gif", "../../site_images/Conv2_on.gif", "../../site_images/Usage_on.gif", "../../site_images/Answer_on.gif", "../../site_images/Word_on.gif", "../../site_images/Download_on.gif", "../../site_images/YHome_on.gif");
	for(loadall=0; loadall<AllImages.length; loadall++){
		var LoadedImage=new Image();
		LoadedImage.src=AllImages[loadall];
	}
}

	function overImage(imageItem){
	image = eval(document.getElementById(imageItem));
	image.src = "../../site_images/"+imageItem+"_on.gif";
}

function outImage(imageItem){
	image = eval(document.getElementById(imageItem));
	image.src = "../../site_images/"+imageItem+"_off.gif";
}
//-->
</script>
<title>Managing URL to StartContext Mapping </title>
</head>

<body style="margin: 0px;" onLoad="preloader();">
<table width="770" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td width="117" valign="top">
		<table border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td><img src="../../images/space.gif" width="1" height="50"></td>
			</tr>
			<tr>
				<td> <span class="left_title">Managing URL to StartContext Mapping </span></td>
			</tr>
			<tr>
				<td><img src="../images/space.gif" width="1" height="5"></td>
			</tr>
			<tr>
				<td><a href="category.php"><img src="../../site_images/Category_on.gif" border="0" id="Category"></a></td>
			</tr>
			<tr>
				<td><a href="conversations.php" onMouseOver="overImage('Conv2');" onMouseOut="outImage('Conv2');"><img src="../../site_images/Conv2_off.gif" border="0" id="Conv2"></a></td>
			</tr>
			<tr>
				<td><a href="usage.php" onMouseOver="overImage('Usage');" onMouseOut="outImage('Usage');"><img src="../../site_images/Usage_off.gif" border="0" id="Usage"></a></td>
			</tr>
			<tr>
				<td><a href="answerFreq.php?botid=<?php echo $BOTID; ?>" onMouseOver="overImage('Answer');" onMouseOut="outImage('Answer');"><img src="../../site_images/Answer_off.gif" border="0" id="Answer"></a></td>
			</tr>
			<tr>
				<td><a href="wordSearch.php" onMouseOver="overImage('Word');" onMouseOut="outImage('Word');"><img src="../../site_images/Word_off.gif" border="0" id="Word"></a></td>
			</tr>
			<tr>
				<td><a href="download/index.php" onMouseOver="overImage('Download');" onMouseOut="outImage('Download');"><img src="../../site_images/Download_off.gif" border="0" id="Download"></a></td>
			</tr>
			<tr>
				<td><a href="../../sign-in.php" onMouseOver="overImage('YHome');" onMouseOut="outImage('YHome');"><img src="../../site_images/YHome_off.gif" border="0" id="YHome"></a></td>
			</tr>
		</table>
	</td>
	<td width="653" align="center">

		<table> <!-- start table to represent right column -->

<!-- start of first inner table -->

		<tr>	<td align="left">
		<table><tr>	<td align="left">
	<br>
	<br>
<?php
echo "display mod is".$display_mode;
if (($display_mode=="new")||($display_mode=="readfile")){
?>

<FORM name="form1" enctype="multipart/form-data" ACTION="readmappingfile.php" METHOD=POST>
<strong>URL to StartContext Mapping File : </strong><br>
The file must be in CSV format with the structure : - URL, Title, StartContext. The header row must not be present.<br>
<INPUT NAME="mapping_file" size="75" TYPE="file">
<INPUT TYPE="submit" VALUE="Read File"><br>
</FORM>
</td></tr>
</table>
</td></tr>
<!-- end  of first inner table -->

<?php
}
?>


<?php
if ($display_mode=="readfile"){
?>
<!-- start of second inner table -->
<tr>	<td align="left">
<table width="250" border="1" cellspacing="0" cellpadding="1" bordercolor="gray" align="left" >
<tr><td>URL</td><td>Title</td><td>StartContext</td></tr>

<?php
foreach($mapping_array as $mapping_array_row)
{
echo "<tr>";
foreach($mapping_array_row as $mapping_array_row_cell){
	echo "<td align=\"left\">";
	if ($mapping_array_row_cell!='')
	echo $mapping_array_row_cell;
	else
		echo "&nbsp";
	echo "</td>";
	}
echo "</tr>";
}
?>
</table>
</td></tr>
<!-- end of second inner table -->

<!-- start of third  inner table -->
<tr><td>
<table border="0" cellpadding="4" cellspacing="2" >
<tr><td>

<!-- <form action="ManageMapping.php" method="post">
<input type="hidden" name="submitted" value="true">

<table>
<!--	<tr>
	<td align="right"><input type="radio" name="dboptions" class="radio" value="replace1"></td>
	<td>Replace existing mappings in the database with the data from the CSV File.</td>
</tr>
<tr>
	<td align="right"><input type="radio" name="dboptions" class="radio" value="append"></td>
	<td>Append existing mappings in the database with the data from CSV File.</td>

<tr> -->

<!--	<tr>
	<td align="right"><input type="checkbox" name="dboptions" class="radio" value="delete"></td>
	<td>Delete existing mappings from the database before loading the data from the CSV File.</td>

<tr>

	<td colspan="2" align="right">		
	<br></td>
</tr>
</table>
<input type="submit" name="submit" class="buttons" value="submit">
</form> -->

</td></tr></table>
</td></tr>
<!-- end of third  inner table -->


<?php
}else if ($display_mode=="dbupdated"){
if ($_SESSION['dbupdated'])
	{
		echo "The mapping into database has been successfully updated.";
	}
}
?>




		</table> <!-- end table to represent right column -->

</td></tr></table>



<FORM name="form2"  action="ManageMapping.php" method="post">
<input type="hidden" name="submitted" value="true">

<input type="checkbox" name="dboptions" value="delete" class="radio">Delete existing mappings from the database before loading the data from the CSV File.
<input type="submit" name="submit" class="buttons" value="submit">
</form> 




</body>
</html>

Thank you , Guys for responding to my query. One solution which works for troublshooting is to take a break. I worked on this problem for continuous two days.. posted at different forums and then finally "almost" gave up. Took a break for couple of hours today and then came back to start looking at the code with a fresh mind. And, within few minutes I realised, when I submit the button, though it get submitted to the php but then due to header redirect code - //header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/ManageMapping.php');it was again being submitted to same php and probably that was the reason for missing POST parameters. I commented out the above header redirection and it works prefectly now.

And, Kudos to aschk, though you mentioned above that header redirect might be the problem, I am sorry, I did not pay that much attention that time.

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.