Link to home
Start Free TrialLog in
Avatar of UniqueData
UniqueDataFlag for United States of America

asked on

form submit not working

I can't see what is wrong with the code below.  I am not getting the message that Dealer Code is required, nor is an email sent or the page redirecting if dealer code is not missing.

I am sure someone else will see my problem immediately :)

<?php 
		$errMessage='test';

        if ( !empty($_POST["sendMessage"])  )
        {
        		if ( empty($_POST["DealerCode"])) {  
    				$errMessage = 'You must enter a Dealer Code' ;
				} else {
					$errMessage='';
					$message = 'test';        		
					/*		
					$message = '';
					foreach($_POST as $key => $value)
					{
					    $message .= $key . ': ' . $value . "<br/>";
					} 
					*/       	
		            // To send HTML mail, the Content-type header must be set
		            $headers  = 'MIME-Version: 1.0' . "\r\n";
		            $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		            $headers .= 'From: dealer submission <test@test.biz>' . "\r\n";
		            mail('test@yahoo.com','Message from Website',$message,$headers);

		        // MESSAGE SENT
		            header("Location: messageSent.php");
		            exit;                   
        		}
        }
?>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

	<style>
		body {
			padding-left: 30px;
		}
		th {
			background-color:#3399FF;
			text-align: center;
		}

		.column-one {
			width: 40px;
			text-align: center;
		}
		.column-two {
			width:450px;
		}
	</style>
	
</head>
<body>
	
	<br />
	<form method="post" action="priceEntry.php">
		<table width='85%'>
			<tr>
				<td>Dealer Code:<input type='text' name='DealerCode' /></td>
				<td><span class="error"><?php echo $errMessage;?></span></td>
				<td><button type="submit" class="btn btn-success" name="sendMessage">Submit</button></td>
			</tr>
		</table>
		<br/>
		<table border='1'>
	        <col class="column-one">
	        <col class="column-two">
	        <col class="column-three">
	        <col class="column-four">
	        <col class="column-five">
			<thead>
			<tr>
				<th></th>
				<th>Maintenance Services</th>
				<th>Price</th>
				<th>Shop Duration Time</th>
				<th>OP Code</th>
			</tr>
			</thead>
			<tr>
				<td>01</td>
				<td>Replace Engine Oil & Filter</td>
				<td><input type='text' name='MaintPrice01' /></td>
				<td><input type='text' name='MaintDuration01' /></td>
				<td><input type='text' name='MaintOPCode01' /></td>
			</tr>
			<tr>
				<td>02</td>
				<td>4 Wheel Alignment</td>
				<td><input type='text' name='MaintPrice02' /></td>
				<td><input type='text' name='MaintDuration02' /></td>
				<td><input type='text' name='MaintOPCode02' /></td>
			</tr>
			<tr>
				<td>03</td>
				<td>Wheel Balance (4 Wheel)</td>
				<td><input type='text' name='MaintPrice03' /></td>
				<td><input type='text' name='MaintDuration03' /></td>
				<td><input type='text' name='MaintOPCode03' /></td>
			</tr>
			<tr>
				<td>04</td>
				<td>Replace Air Cleaner Filter</td>
				<td><input type='text' name='MaintPrice04' /></td>
				<td><input type='text' name='MaintDuration04' /></td>
				<td><input type='text' name='MaintOPCode04' /></td>
			</tr>
			<tr>
				<td>05</td>
				<td>Replace Automatic Transaxle Fluid</td>
				<td><input type='text' name='MaintPrice05' /></td>
				<td><input type='text' name='MaintDuration05' /></td>
				<td><input type='text' name='MaintOPCode05' /></td>
			</tr>
			<tr>
				<td>06</td>
				<td>Replace Climate Control Air Filter</td>
				<td><input type='text' name='MaintPrice06' /></td>
				<td><input type='text' name='MaintDuration06' /></td>
				<td><input type='text' name='MaintOPCode06' /></td>
			</tr>
			<tr>
				<td>07</td>
				<td>Replace Coolant</td>
				<td><input type='text' name='MaintPrice07' /></td>
				<td><input type='text' name='MaintDuration07' /></td>
				<td><input type='text' name='MaintOPCode07' /></td>
			</tr>
			<tr>
				<td>08</td>
				<td>Replace Fuel Filter</td>
				<td><input type='text' name='MaintPrice08' /></td>
				<td><input type='text' name='MaintDuration08' /></td>
				<td><input type='text' name='MaintOPCode08' /></td>
			</tr>
			<tr>
				<td>09</td>
				<td>Replace Fuel Tank Air Filter</td>
				<td><input type='text' name='MaintPrice09' /></td>
				<td><input type='text' name='MaintDuration09' /></td>
				<td><input type='text' name='MaintOPCode09' /></td>
			</tr>
			<tr>
				<td>10</td>
				<td>Replace Rear Axle Fluid</td>
				<td><input type='text' name='MaintPrice10' /></td>
				<td><input type='text' name='MaintDuration10' /></td>
				<td><input type='text' name='MaintOPCode10' /></td>
			</tr>
			<tr>
				<td>11</td>
				<td>Replace Spark Plugs</td>
				<td><input type='text' name='MaintPrice11' /></td>
				<td><input type='text' name='MaintDuration11' /></td>
				<td><input type='text' name='MaintOPCode11' /></td>
			</tr>
			<tr>
				<td>12</td>
				<td>Tire Rotation</td>
				<td><input type='text' name='MaintPrice12' /></td>
				<td><input type='text' name='MaintDuration12' /></td>
				<td><input type='text' name='MaintOPCode12' /></td>
			</tr>
			<tr>
				<td>13</td>
				<td>Replace Wiper Blades</td>
				<td><input type='text' name='MaintPrice13' /></td>
				<td><input type='text' name='MaintDuration13' /></td>
				<td><input type='text' name='MaintOPCode13' /></td>
			</tr>
			<tr>
				<td>14</td>
				<td>Brake System Fluid Replacement</td>
				<td><input type='text' name='MaintPrice14' /></td>
				<td><input type='text' name='MaintDuration14' /></td>
				<td><input type='text' name='MaintOPCode14' /></td>
			</tr>
			<tr>
				<td>15</td>
				<td>Replace Spark Plugs (Iridium)</td>
				<td><input type='text' name='MaintPrice15' /></td>
				<td><input type='text' name='MaintDuration15' /></td>
				<td><input type='text' name='MaintOPCode15' /></td>
			</tr>
			<tr>
				<td>16</td>
				<td>Air Conditioning Service</td>
				<td><input type='text' name='MaintPrice16' /></td>
				<td><input type='text' name='MaintDuration16' /></td>
				<td><input type='text' name='MaintOPCode16' /></td>
			</tr>
		</table>

		<br /><br />
		<table border='1'>
			<col class="column-one">
	        <col class="column-two">
	        <col class="column-three">
	        <col class="column-four">
	        <col class="column-five">
			
			<tr>
				<th></th>
				<th>Repair Services</th>
				<th>Price</th>
				<th>Shop Duration Time</th>
				<th>OP Code</th>
			</tr>

			<tr>
				<td>01</td>
				<td>ABS Light Diagnosis</td>
				<td><input type='text' name='RepairPrice01' /></td>
				<td><input type='text' name='RepairDuration01' /></td>
				<td><input type='text' name='RepairOPCode01' /></td>
			</tr>		
			<tr>
				<td>02</td>
				<td>Body Appearance and/or Paint Concern</td>
				<td><input type='text' name='RepairPrice02' /></td>
				<td><input type='text' name='RepairDuration02' /></td>
				<td><input type='text' name='RepairOPCode02' /></td>
			</tr>
			<tr>
				<td>03</td>
				<td>Brake System Diagnosis</td>
				<td><input type='text' name='RepairPrice03' /></td>
				<td><input type='text' name='RepairDuration03' /></td>
				<td><input type='text' name='RepairOPCode03' /></td>
			</tr>		
			<tr>
				<td>04</td>
				<td>Check Engine Light Diagnosis</td>
				<td><input type='text' name='RepairPrice04' /></td>
				<td><input type='text' name='RepairDuration04' /></td>
				<td><input type='text' name='RepairOPCode04' /></td>
			</tr>		
			<tr>
				<td>05</td>
				<td>Electrical System Diagnosis</td>
				<td><input type='text' name='RepairPrice05' /></td>
				<td><input type='text' name='RepairDuration05' /></td>
				<td><input type='text' name='RepairOPCode05' /></td>
			</tr>		
			<tr>
				<td>06</td>
				<td>Engine Diagnosis (Noise, Leaks, Other)</td>
				<td><input type='text' name='RepairPrice06' /></td>
				<td><input type='text' name='RepairDuration06' /></td>
				<td><input type='text' name='RepairOPCode06' /></td>
			</tr>		
			<tr>
				<td>07</td>
				<td>Engine Performance Diagnosis (Running Rough, Other)</td>
				<td><input type='text' name='RepairPrice07' /></td>
				<td><input type='text' name='RepairDuration07' /></td>
				<td><input type='text' name='RepairOPCode07' /></td>
			</tr>		
			<tr>
				<td>08</td>
				<td>Heating or Air Conditioning Diagnosis</td>
				<td><input type='text' name='RepairPrice08' /></td>
				<td><input type='text' name='RepairDuration08' /></td>
				<td><input type='text' name='RepairOPCode08' /></td>
			</tr>		
			<tr>
				<td>09</td>
				<td>Squeaks & Rattles Diagnosis</td>
				<td><input type='text' name='RepairPrice09' /></td>
				<td><input type='text' name='RepairDuration09' /></td>
				<td><input type='text' name='RepairOPCode09' /></td>
			</tr>		
			<tr>
				<td>10</td>
				<td>Steering Diagnosis</td>
				<td><input type='text' name='RepairPrice10' /></td>
				<td><input type='text' name='RepairDuration10' /></td>
				<td><input type='text' name='RepairOPCode10' /></td>
			</tr>		
			<tr>
				<td>11</td>
				<td>Suspension Diagnosis</td>
				<td><input type='text' name='RepairPrice11' /></td>
				<td><input type='text' name='RepairDuration11' /></td>
				<td><input type='text' name='RepairOPCode11' /></td>
			</tr>		
			<tr>
				<td>12</td>
				<td>Transmission Diagnosis (Not Shifting Properly, Leaks, Other)</td>
				<td><input type='text' name='RepairPrice12' /></td>
				<td><input type='text' name='RepairDuration12' /></td>
				<td><input type='text' name='RepairOPCode12' /></td>
			</tr>		
			<tr>
				<td>13</td>
				<td>Trim or Moulding Diagnosis</td>
				<td><input type='text' name='RepairPrice13' /></td>
				<td><input type='text' name='RepairDuration13' /></td>
				<td><input type='text' name='RepairOPCode13' /></td>
			</tr>		
			<tr>
				<td>14</td>
				<td>Battery Concern</td>
				<td><input type='text' name='RepairPrice14' /></td>
				<td><input type='text' name='RepairDuration14' /></td>
				<td><input type='text' name='RepairOPCode14' /></td>
			</tr>		
			<tr>
				<td>15</td>
				<td>Light/Bulb Concern</td>
				<td><input type='text' name='RepairPrice15' /></td>
				<td><input type='text' name='RepairDuration15' /></td>
				<td><input type='text' name='RepairOPCode15' /></td>
			</tr>		
			<tr>
				<td>16</td>
				<td>Interior Body or Trim</td>
				<td><input type='text' name='RepairPrice16' /></td>
				<td><input type='text' name='RepairDuration16' /></td>
				<td><input type='text' name='RepairOPCode16' /></td>
			</tr>		
			<tr>
				<td>17</td>
				<td>Audio Diagnosis</td>
				<td><input type='text' name='RepairPrice17' /></td>
				<td><input type='text' name='RepairDuration17' /></td>
				<td><input type='text' name='RepairOPCode17' /></td>
			</tr>		
			<tr>
				<td>18</td>
				<td>Axle, Differential, Drivetrain Diagnosis</td>
				<td><input type='text' name='RepairPrice18' /></td>
				<td><input type='text' name='RepairDuration18' /></td>
				<td><input type='text' name='RepairOPCode18' /></td>
			</tr>		
			<tr>
				<td>19</td>
				<td>Engine Cooling Concern</td>
				<td><input type='text' name='RepairPrice19' /></td>
				<td><input type='text' name='RepairDuration19' /></td>
				<td><input type='text' name='RepairOPCode19' /></td>
			</tr>		
			<tr>
				<td>20</td>
				<td>Muffler/Exhaust System Diagnosis</td>
				<td><input type='text' name='RepairPrice20' /></td>
				<td><input type='text' name='RepairDuration20' /></td>
				<td><input type='text' name='RepairOPCode20' /></td>
			</tr>		
			<tr>
				<td>21</td>
				<td>SRS/Airbag Diagnosis</td>
				<td><input type='text' name='RepairPrice21' /></td>
				<td><input type='text' name='RepairDuration21' /></td>
				<td><input type='text' name='RepairOPCode21' /></td>
			</tr>		
		</table>
		
	</form>
</body>
</html>

Open in new window

Avatar of Kimputer
Kimputer

Sadly, I tested your code and it's working fine. Calling/navigating to the file does nothing of course (as per your own directive), but submitting does work as expected.

Usually I do this with the code when trying to figure out what's wrong:

<?php 
		$errMessage='test';
		echo  $_POST["sendMessage"] . $_POST["DealerCode"];
		
        if ( !empty($_POST["sendMessage"])  )
        {		echo "inside if loop1";
        		if ( empty($_POST["DealerCode"])) {  
					echo "inside if loop2";
    				$errMessage = 'You must enter a Dealer Code' ;
				} else {
					echo "inside if loop3";
					$errMessage='';
					$message = 'test';        		
					/*		
					$message = '';
					foreach($_POST as $key => $value)
					{
					    $message .= $key . ': ' . $value . "<br/>";
					} 
					*/       	
		            // To send HTML mail, the Content-type header must be set
		            $headers  = 'MIME-Version: 1.0' . "\r\n";
		            $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		            $headers .= 'From: dealer submission <test@test.biz>' . "\r\n";
		            mail('test@yahoo.com','Message from Website',$message,$headers);

		        // MESSAGE SENT
		            header("Location: messageSent.php");
		            exit;                   
        		}
        }
?>

Open in new window


However, in this case it didn't help for me, as it worked as it should. So in essence, I saw all the echo which I wanted to see, when they were expected.

What PHP version is running on the server?
Avatar of UniqueData

ASKER

Odd thing is I have another page on the same server (I use Surpass Hosting) that works just fine, in fact the code I posted came from that other working page originally.  

I tried your echo technique.  The only thing that seemed to work was:  echo  $_POST["sendMessage"] . $_POST["DealerCode"];

however, it just seemed to only echo the DealerCode.   should I have seen 'True' or something like that for Post["sendMessage"] ?
I use this simple program to see all of the values that are submitted from a POST form.  I call it 'postdump.php'.  Substitute it for the 'action' page in your form to see everything you are sending.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>POST Dump</title>
</head>
<body>
<pre>
<?php 
var_dump($_POST);
foreach($_POST as $key => $value) {
    echo $key.' = '.$value."<br>";
}

?>
</pre>
</body>
</html>

Open in new window

When page is loaded (without submit, just navigating) = $_POST["sendMessage"] = empty
When page is submitted to itself = $_POST["sendMessage"] = Submit

Therefore I think you use another php file to post it? Check the  submit code there is the same as this file (as this file is theoratically correctly coded).
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good catch, that is definitely the solution.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When you're not sure what a variable contains, var_dump() is your friend.

If you want to see the POST-method request variables, use var_dump($_POST);

This may be a useful reference:
http://php.net/manual/en/language.variables.external.php
That was it.  I forgot the value='submit'.

thought it was something simple :)

Thanks