Hi Guys,
Im Having a spot of bother, when i submit my first form it gets emailed, but it shouldnt. The second form should only be emailed once submitted. The second form works fine. but why does the first form get emailed. How do i stop it from getting emailed
here is my code
<html>
<head>
</head>
<body>
<?php
set_time_limit(0);
$jobId=$_GET['jobId'];
mysql_connect("localhost","phpuser","phpuser03") or die ("Database connection error");
mysql_select_db( helpdesk);
$sql = "select jobId, email, room, computers, description, date FROM requests_table
WHERE requests_table.jobId='$jobId'";
$result = mysql_query($sql);
//echo mysql_error() ;
echo "<table>\n";
echo " <tr>\n";
echo " <th><b>JobID</b></th>\n";
echo " <th><b>email</b></th>\n";
echo " <th><b>Room</b></th>\n";
echo " <th><b>Computers</b></th>\n";
echo " <th><b>description</b></th>\n";
echo " <th><b>date & time</b></th>\n";
echo " </tr>\n";
while ($row = mysql_fetch_array($result)) {
echo '<td>'.$row['jobId'].'</td>';
echo '<td>'.$row['email'].'</td>';
echo '<td>'.$row['room'].'</td>';
echo ' <td>'.$row['computers'].'</td>'."\n";
echo ' <td>'.$row['description'].'</td>'."\n";
echo ' <td>'.$row['date'].'</td>'."\n";
echo '</tr>'."\n";
echo '</table>';
}
?>
<br>
<br>
<form name="details" method="post" action= "<? echo $SERVER['PHP_SELF'] . "?jobId=" . $jobId; ?>">
<table width="374" height="160" border="0">
<tr>
<th width="54" scope="row">TechId</th>
<td width="250"><strong>Action taken </strong></td>
<td width="56"> </td>
</tr>
<tr>
<th scope="row"><input name="Tech_initals" type="text" size="8" maxlength="5"></th>
<td><textarea name="action_taken" cols="35" rows="5"></textarea></td>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td><input type="submit" name="Submit1" value="Submit"></td>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
</tr>
</table>
</form>
<form name="emailform" method="post" action="<?=$SERVER['PHP_SELF']?>?jobId=<?=$GET['jobId']?>">
<!-- <form name="emailform" method="post" action=" //echo $SERVER['PHP_SELF'] ?>">-->
<table width="374" height="160" border="0">
<tr>
<th width="54" scope="row">Status of job </th>
<td width="250"><strong>Email comment </strong></td>
<td width="56"> </td>
</tr>
<?php
if($SERVER['REQUEST_METHOD'] == "POST") {
$sql = "SELECT email FROM requests_table WHERE jobId='".$GET['jobId']."'";
//$sql = "SELECT email FROM requests_table WHERE jobId='$jobId'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
//echo $sql;
// print_r($row);
$to = $row['email'];
$from = "poo@ntlworld.com";
$message = $_POST['action_taken'];
mail($to, "technical services", $message,
"From: {$from}\r\n"
."Reply-To: {$from}\r\n"
."X-Mailer: PHP/" . phpversion());
}
?>
<tr>
<th scope="row"><input name="techId" type="text" size="8" maxlength="5"></th>
<td><textarea name="action_taken" cols="35" rows="5"></textarea></td>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td><input type="submit" name="Submit" value="Submit">
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
</tr>
</table>
</form>
<?php
$color[0] = "FCFCFC";
$color[1] = " 34ADE5 ";
$jobId=$GET['jobId'];
$action_taken=$GET['action_taken'];
$Tech_initals=$_GET['Tech_intials'];
if($_POST["Submit1"]) {
$action_taken = addslashes($POST['action_taken']);
$Tech_initals = addslashes($POST['Tech_initals']);
$db = @mysql_connect('localhost', 'phpuser', 'phpuser03') or die('Could not connect to the database: '.mysql_error());
@mysql_select_db('helpdesk') or die('Could not select the database: '.mysql_error());
$result = mysql_query("INSERT INTO tech_table (jobId, Tech_initals, action_taken, date)
VALUES ('$jobId', '$Tech_initals', '$action_taken', NOW())") or die("Unable to insert record: " . mysql_error());
}
$sql = "SELECT jobId, Tech_initals, action_taken, date FROM tech_table ";
$result = mysql_query($sql);
echo "<table>\n";
echo " <tr>\n";
echo " <th><b>JobID</b></th>\n";
echo " <th><b>Tech Initals</b></th>\n";
echo " <th><b>Action taken</b></th>\n";
echo " <th><b>Date</b></th>\n";
echo " </tr>\n";
while ($row = mysql_fetch_array($result)) {
//print_r($result) ;
// echo mysql_error() ;
$a = ($a+1)%2;
echo '<tr bgcolor='.$color[$a] . ">\n";
echo '<td>'.$row['jobId'].'</td>';
echo ' <td>'.$row['Tech_initals'].'</td>'."\n";
echo ' <td>'.$row['action_taken'].'</td>'."\n";
echo ' <td>'.$row['date'].'</td>'."\n";
echo '</tr>'."\n";
//echo '</table>';
}
?>
</body>
</html>