Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Method Post doesn't work, Get does

Status
Not open for further replies.

micknh

Programmer
Apr 19, 2005
13
US
Hi,

I have a form on a PHP page that will display data from a mysql database when I have the action on the form set to Get but not when sent to Post.

This is on a Win2k server loader with IIS5.
PHP 5.0.4

Running the same code on a test Win2003 server with IIS6 and PHP 5.0.3 works without a problem.

Guess which server I have to use as my web server for Production?

Code:
//Paginator
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
} 
//echo 'Page Count: '.$_GET['page'];
// Define the number of results per page
$max_results = 10;

// Figure out the limit for the query based
// on the current page number.
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
				  ?>
				  <link href="../css/nh.css" rel="stylesheet" type="text/css">
<?php 
if (!isset($_POST['submit']) && (!isset($_GET['page']))) {
?>
    <p>&nbsp;</p>
	
	 <form action="PropSearch.php" method="post">
	<table>
    <tr><td><font color="#FF0000">*</font> Last Name or Company: </td><td><input name="ln" size="30" type="text">
	Exact<input name="lnExact" type="checkbox"></td></tr>
	<tr><td>First Name: </td><td><input name="fn" type="text"></td></tr>
	  <tr><td><!-- <font color="#FF0000">**</font> -->City: </td><td><input name="city" type="text"></td></tr>
	<tr><td><!-- <font color="#FF0000">**</font> -->Company Holding Property: </td><td><input name="holder" type="text"> 
	</td></tr>
	</table>
    <input type="submit" name="submit" value="Search">
	<p><font color="#FF0000">*</font> Required Field</p>
<!-- 	 <p><font color="#FF0000">**</font> Not Implemented Yet</p> 
 -->    </form> 
	<?php for($i = 1; $i <= 7; $i++){
    echo '<p>&nbsp;</p>';
}
?>
<?php

 } //if (!isset($_POST['submit'])) {
else { //if (!isset($_POST['submit'])) {
	if (!isset($_GET['page'])) {
	$_SESSION['ln'] = $_POST['ln'];
	$_SESSION['fn'] = $_POST['fn'];
	$_SESSION['city'] = $_POST['city'];
	$_SESSION['refExact'] = $_POST['refExact'];
	$_SESSION['lnExact'] = $_POST['lnExact'];
	
	}
	$IncludeMe = 'db.php';
					include($IncludeMe);
	?>

Any Suggestions?

Sincerely,

Michael
 
Where is the query for the database?

Guess which server I have to use as my web server for Production?

Obvious: Apache, php, mysql, Linux.

Put IIS and Windows in the right place: the trash.

Cheers.
 
The statement where I open the data connection is:
Code:
<?php $mysqli = new mysqli(<ipaddress>, <username>, <password>);

	/* check connection */
	if (mysqli_connect_errno()) {  //2
	   printf("Connect failed: %s\n", mysqli_connect_error());
	   exit();
	}  //if (mysqli_connect_errno()) { //2
	?>

I access that page from an included php file which is in the include path in php.ini and the file is also in the same directory as the original php file.
The rest of the code including the query follows:
Code:
	if (!isset($_GET['page'])) {
	$_SESSION['ln'] = $_POST['ln'];
	$_SESSION['fn'] = $_POST['fn'];
	$_SESSION['city'] = $_POST['city'];
	$_SESSION['refExact'] = $_POST['refExact'];
	$_SESSION['lnExact'] = $_POST['lnExact'];
	
	}
	$IncludeMe = 'db.php';
					include($IncludeMe);
	?>
	<!-- Refine Search Table -->
	<br />
	<p><span class="SubSectionLabel">Refine Search</span></p>
	<div name="RefineSearch">
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
	<table width="100%" bgcolor="#399608" cellpadding="1" cellspacing="0">
	<tr ><th width="30%" style="color:cornsilk; font-size:12px">Last Name</th>
	<th width="25%" style="color:cornsilk; font-size:12px">First Name</th>
	<th width="25%" style="color:cornsilk; font-size:12px">City</th>
	<th width="20%" style="color:cornsilk; font-size:12px;">Exact
	<input name="refExact" type="checkbox"></th></tr>
	<tr>
	<td><input type="text" name="ln" size="20" value="<?php echo $_SESSION['ln'] ?>"></td>
	<td><input type="text" name="fn"  size="15" value="<?php echo $_SESSION['fn'] ?>"></td>
	<td><input type="text" name="city"  size="15" value="<?php echo $_SESSION['city'] ?>"></td>
	<td><input type="submit" name="submit" value="Refine Search"></td>
	</tr>
	</table>
	</form>
	</div>
	<?php
	//Send a query to the server
	if (!isset($_SESSION['lnExact'])) {
		if (!isset($_SESSION['lnExact'])) {
		$_SESSION['strWhere']=" where lname like '%".$_SESSION['ln']."%' ";
		}
		else {
		$_SESSION['strWhere'] =" where lname = '".$_SESSION['ln']."' ";
		}
	} //if (!isset($_POST['lnExact'])) {
	else {
		$_SESSION['strWhere'] =" where lname = '".$_SESSION['ln']."' ";
	}  //else {
	if (empty($_SESSION['fn'])) {
		$_SESSION['strFN']="";
	}  //if (!isset($_POST['fn'])) {
	else {
		if (!isset($_SESSION['refExact'])) {
		$_SESSION['strFN']=" AND fname like '".$_SESSION['fn']."%' ";
		}
		else {
		$_SESSION['strFN']=" AND fname = '".$_SESSION['fn']."' ";
		}
		//$strFN=" AND fname like '%$fn%' ";
	} //else {
	
	if (empty($_SESSION['city'])) {
		$_SESSION['strCity']="";
	}  //if (!isset($_POST['fn'])) {
	else {
	if (!isset($_SESSION['refExact'])) {
		$_SESSION['strCity']=" AND OWNERS.city like '".$_SESSION['city']."%' ";
		}
		else {
		$_SESSION['strCity']=" AND OWNERS.city = '".$_SESSION['city']."' ";
		}
		//$strCity=" AND OWNERS.city like '%$city%' ";
	} //else {
	If ($page == 1){
	$qcount = 'Select owners.ownerid from owners'.$_SESSION['strWhere'].$_SESSION['strFN'].$_SESSION['strCity'];
	//echo $qcount;
	 $_SESSION['LastSQL'] = $qcount;
	$count=mysqli_query($mysqli,$qcount);
	If ($count) {
$_SESSION['counted'] = mysqli_num_rows($count);
	//echo 'Counted: '.$counted;
	}
	}
	$SqlStr = "Select owners.PropertyID,owners.lname, owners.fname, ";
	$SqlStr = $SqlStr."CONCAT(owners.lname,',',owners.fname) AS nameo, ";
	$SqlStr = $SqlStr."owners.addr1, owners.city, owners.state,  ";
	$SqlStr = $SqlStr."properties.amount, properties.proptype, holders.holder ";
	$SqlStr = $SqlStr."from owners inner join properties ";
	$SqlStr = $SqlStr."on owners.PropertyID = properties.PropertyID ";
	$SqlStr = $SqlStr."INNER JOIN holders ";
	$SqlStr = $SqlStr."ON properties.holderid = holders.holderid ";	
	$SqlStr= $SqlStr.$_SESSION['strWhere'].$_SESSION['strFN'].$_SESSION['strCity'];
	$SqlStr= $SqlStr." order by nameo asc limit ".$from.",".$max_results;
	 $_SESSION['LastSQL'] = $SqlStr;
	//Get the resultset
	$result=mysqli_query($mysqli, $SqlStr);
	if ($result){
		
	 
		//$QueryRowcCount = 1;
		//print("Properties : \n<br><br>");
		//Fetch the result of the query
		echo '<br /><br /><span class="SubSectionLabel">Search Results</span><br>';
		
		$totalrows = mysqli_num_rows($result);
		If ($totalrows > 0){
		echo '<table><tr><th>Name</th><th>Last Known Address</th>';
		echo '<th>Reported By</th><th>Amount</th></tr>';
		}
		else {
		echo '<p class="Subheader">No Results to Display.  Please refine your search</p>';
		}
		?>
		
		<?php
		while($row=mysqli_fetch_assoc($result)){
			if (!isset($QueryRowCount))
			{$QueryRowCount = 0;
			}
			if (!isset($BackColor))
			{$BackColor = 'white';
			}
			$QueryRowCount++;
			$Modulus = $totalrows % $QueryRowCount;
			
			if($BackColor !="white") {  //if($BackColor !="white")
				$BackColor="white";
				} //if($BackColor !="white")
			else {
				$BackColor="cornsilk";
				} //if($BackColor !="white")
			
			echo '<tr bgcolor="'.$BackColor.'"';
			echo " onMouseOver='";
			echo 'this.style.background="cadetblue"'."'";
			echo " onMouseOut='";
			echo 'this.style.background="'.$BackColor.'"'."'>";
			
			
			echo '<td class="APtext">';
			//echo '<a href="ShowProp.php?PID='. $row['PropertyID'].'"';
			//echo ' onMouseOver="window.status='."'Click the link to view information about this property'".';return true;" ';
			//echo 'onMouseOut="window.status='."'New Hampshire State Treasury'".';return true;">';
			//echo '<acronym title="Click the Detail Button to view Property Information" class="noline">';
			
			echo '<div style="font-size:12px; cursor:pointer; color:#333300" onClick="window.location=';
			
			echo "'ShowProp.php?PID=";
			echo $row['PropertyID'];
			echo "'";
			echo '">';
			$displayname = $row['lname'];
			if (!empty($row['fname'])) {
			 $displayname .= ", ".$row['fname'];
			 }
			//$displayname = substr($displayname,0,20);
			//echo  $displayname. "<br /> ";
	echo '<acronym title="Click here to view Property Information" class="noline">';
	echo $displayname;
			echo '&nbsp;<img src="../../images/Mag1.jpg" alt="See More Information about this Property">';
			echo '</acronym>';
			//echo '<button onClick="window.location='."'ShowProp.php?PID=".$row['PropertyID']."'".'">Details</button></acronym>';
			echo '</div>';
			//echo "</a>";
			echo "</td>";
			$OAddr = "";
			/* $checkvar = $row['addr1'];
			if (empty($checkvar)) {}
			//$OAddr = "";
			//}
			else { //if (empty($checkvar)) 
			$OAddr = trim($row['addr1'])."<br>";
			} //if (empty($checkvar)) */ 
			$OAddr = 'Not Disclosed<br />';
			$checkvar = $row['city'];
			if (empty($checkvar)) {}
			else { //else 
			$OAddr = $OAddr.trim($row['city']);
				$checkvar = $row['state'];
				if (empty($checkvar)) {}
				else {
					$OAddr = $OAddr.', ';
				}  //else {
			} //else
			$checkvar = $row['state'];
			if (empty($checkvar)) {}
			else {
			$OAddr = $OAddr.trim($checkvar);
			} //else {
			if (empty($OAddr)) {
				$OAddr = "Not Disclosed";
			} //if (empty($OAddr))
			echo '<td class="APtext">'.$OAddr.'</td><td class="APtext">';
			//$holder = substr($row['holder'],0,20);
			$holder = $row['holder'];
			echo $holder.'</td><td class="APtext">';
			$propertytype = $row['proptype'];
			if ($propertytype == 'SC')
				{//A stock Property Type
				echo 'Stock Transaction';
				}
			else{
			$checkvar = $row['amount'];
			switch ($checkvar) {
				case ($checkvar <100):
   					echo "Under $100";
					break;
				case ($checkvar >100):
   					echo "Over $100";
					break;
				default:
  					 echo "Undisclosed";
					 
			}
			}
			echo '</td></tr>';
		}
		//echo "<td>".$row['city']. "</td></tr>";
	} //while($row=mysqli_fetch_assoc($result)){
	echo "</table>";
 
it's weird, I see no problem with your code... may be a bug in php or IIS?

If someone have another opinion, they are welcome.

Cheers.
 
Did you invoke session_start(); before you started working with session variables?
 
Thanks for your replies.

Chacalinc, I am wondering if it is a bug also.

Vragabond, I did invoke session_start() at the beginning of the page and this is the index page for this directory.

I am going to try creating a simple form with a post action and see if I can duplicate or see how to make it work.

Any suggestions would be greatly appreciated.
 
This is a long shot but, you are checking if $_GET['page'] exists and then inserting things from the $_POST array. Are you sending the page variable separately through form's action? I would suggest you print out the $_POST array at the beggining to see if it carries anything.
Code:
echo '<pre>';
print_r ($_POST);
echo '</pre>';
 
What is happening is the initial view of the page is the standard form.

They click submit and then the record set is pulled with matching records from the query.

I am breaking down the result set into groups of 10. I am creating links at the bottom of the page and concatenating the link with the page number in the url string.

I will try your suggestion. If I put that at the top of the page will it process the print_r request before parsing the rest of the page?
 
I created a very simple form called TestForm.php .

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test Form</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr><td>Name</td><td><input type="text" name="name0"/></td></tr>
<tr><td>Age</td><td><input type="text" name="age0"/></td></tr>
</table>
<input type="submit" name="SubmitMe" value="Submitted" />
</form>
</body>
</html>

I first set the method for the form to GET and the page loaded again after the submit.
When I changed the method back to POST, I received a Page Not Found error page.
I created another page testform3.php to display the Form Values after submit. I changed the action on the form to testform3.php. On Testform3 I did what Vragabond suggested but still received the same error page?

I am frustrated.
Once again the particulars of this server.
Windows 2k Server SP4
IIS 5
PHP 5.04
MySQL 4.1.11
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top