I have a problem with my contact form. When the data is sent, I would like to have the fields blank again. I've tried a lot but nothing works.
Here is the script to send the mail:
<?php
error_reporting(0);
session_start();
if ("post" === strtolower($_SERVER['REQUEST_METHOD'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$adres = $_POST['adres'];
$postcode = $_POST['postcode'];
$woonplaats = $_POST['woonplaats'];
$telefoon = $_POST['telefoon'];
$dag = $_POST['dag'];
$dag_nummer = $_POST['dag_nummer'];
$maand = $_POST['maand'];
$tijd = $_POST['tijd'];
$opmerking = $_POST['opmerking'];
$_SESSION['name'] = $name;
$_SESSION['email'] = $email;
$_SESSION['adres'] = $adres;
$_SESSION['postcode'] = $postcode;
$_SESSION['woonplaats'] = $woonplaats;
$_SESSION['telefoon'] = $telefoon;
$_SESSION['dag'] = $dag;
$_SESSION['dag_nummer'] = $dag_nummer;
$_SESSION['maand'] = $maand;
$_SESSION['tijd'] = $tijd;
$_SESSION['opmerking'] = $opmerking;
if (empty($name) || empty($email) || empty($telefoon) || empty($tijd)) {
if (empty($name)) {
$errors[] = "name";
}
if (empty($email)) {
$errors[] = "email";
}
if (empty($telefoon)) {
$errors[] = "telefoon";
}
if (empty($tijd)) {
$errors[] = "tijd";
}
header("Location: afspraak.php?error[]=" .implode('&error[]=', $errors));
exit;
} else {
// send mail if (post) parameters are correct
mail(
'tim-luijten#hotmail.com',
'Afsprakenformulier o-vita.nl',
"Er is contact opgenomen via het afsprakenformulier. Zie onderstaande gegevens: \n\n
Naam: {$name} \n
E-mailadres: {$email} \n
Adres: {$adres} \n
Postcode: {$postcode} \n
Woonplaats: {$woonplaats} \n
Telefoonnummer: {$telefoon} \n
Datum: {$dag} - {$dag_nummer} - {$maand} \n
Tijd: {$tijd} \n
Opmerking: {$opmerking} \n"
,
"From: {$email} \r\n"
);
header("Location: bedankt_afspraak.php");
exit;
}
}
header("Location: afspraak.php");
?>
The form:
<form action="afspraak_verstuur.php" method="post" name="contact_form">
<table width="300" border="0">
<tr>
<td class="tabform">Naam*:</td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<input name="name" type="text" class="text_veld" value="<?php echo (isset($_SESSION['name'])) ? $_SESSION['name'] : ""; ?>" /></td>
</tr>
<?php if (in_array('name', $_GET['error'])) { ?>
<tr>
<td colspan="2">
<font color="red">Er is geen naam ingevuld</font>
</td>
</tr>
<?php } ?>
<tr>
<td class="tabform">E-mail*:</td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<input name="email" type="text" class="text_veld" value="<?php echo (isset($_SESSION['email'])) ? $_SESSION['email'] : ""; ?>" />
</td>
</tr>
<?php if (in_array('email', $_GET['error'])) { ?>
<tr>
<td colspan="2">
<font color="red">Er is geen e-mailadres ingevuld</font>
</td>
</tr>
<?php } ?>
<tr>
<tr>
<td class="tabform">Adres:</td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<input name="adres" type="text" class="text_veld" value="<?php echo (isset($_SESSION['adres'])) ? $_SESSION['adres'] : ""; ?>" />
</td>
</tr>
<?php if (in_array('adres', $_GET['error'])) { ?>
<tr>
<td colspan="2">
<font color="red">Er is geen adres ingevuld</font>
</td>
</tr>
<?php } ?>
<tr>
<tr>
<td class="tabform">Postcode:</td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<input name="postcode" type="text" class="text_veld" value="<?php echo (isset($_SESSION['postcode'])) ? $_SESSION['postcode'] : ""; ?>" />
</td>
</tr>
<?php if (in_array('postcode', $_GET['error'])) { ?>
<tr>
<td colspan="2">
<font color="red">Er is geen postcode ingevuld</font>
</td>
</tr>
<?php } ?>
<tr>
<tr>
<td class="tabform">Woonplaats:</td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<input name="woonplaats" type="text" class="text_veld" value="<?php echo (isset($_SESSION['woonplaats'])) ? $_SESSION['woonplaats'] : ""; ?>" />
</td>
</tr>
<?php if (in_array('woonplaats', $_GET['error'])) { ?>
<tr>
<td colspan="2">
<font color="red">Er is geen woonplaats ingevuld</font>
</td>
</tr>
<?php } ?>
<tr>
<tr>
<td class="tabform">Telefoon*:</td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<input name="telefoon" type="text" class="text_veld" value="<?php echo (isset($_SESSION['telefoon'])) ? $_SESSION['telefoon'] : ""; ?>" />
</td>
</tr>
<?php if (in_array('telefoon', $_GET['error'])) { ?>
<tr>
<td colspan="2">
<font color="red">Er is geen telefoonnummer ingevuld</font>
</td>
</tr>
<?php } ?>
<tr>
<tr>
<td class="tabform">Datum*:</td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<select name="dag" type="text" class="text_dag" value="Selecteer een dag" />
<option value="maandag">maandag</option>
<option value="dinsdag">dinsdag</option>
<option value="woensdag">woensdag</option>
<option value="donderdag">donderdag</option>
<option value="vrijdag">vrijdag</option>
<option value="zaterdag">zaterdag</option>
</select>
<?php echo (isset($_SESSION['dag'])) ? $_SESSION['dag'] : ""; ?>
<select name="dag_nummer" type="text" class="text_dag_nummer" value="1" />
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<?php echo (isset($_SESSION['dag_nummer'])) ? $_SESSION['dag_nummer'] : ""; ?>
<select name="maand" type="text" class="text_maand" value="Januari" />
<option value="januari">januari</option>
<option value="februari">februari</option>
<option value="maart">maart</option>
<option value="april">april</option>
<option value="mei">mei</option>
<option value="juni">juni</option>
<option value="juli">juli</option>
<option value="augustus">augustus</option>
<option value="september">september</option>
<option value="oktober">oktober</option>
<option value="november">november</option>
<option value="december">december</option>
</select>
<?php echo (isset($_SESSION['maand'])) ? $_SESSION['maand'] : ""; ?>
</td>
</tr>
<?php if (in_array('datum', $_GET['error'])) { ?>
<tr>
<td colspan="2">
<font color="red">Er is geen datum ingevuld</font>
</td>
</tr>
<?php } ?>
<tr>
<tr>
<td class="tabform">Tijd*:</td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<input name="tijd" type="text" class="text_veld" value="<?php echo (isset($_SESSION['tijd'])) ? $_SESSION['tijd'] : ""; ?>" />
</td>
</tr>
<?php if (in_array('tijd', $_GET['error'])) { ?>
<tr>
<td colspan="2">
<font color="red">Er is geen tijd ingevuld</font>
</td>
</tr>
<?php } ?>
<tr>
<tr>
<td class="tabform">Opmerking:</td>
<td> </td>
</tr>
<tr>
<td height="60" colspan="2">
<textarea name="opmerking" type="text" class="text_comments" rows="4" value="" /><?php echo (isset($_SESSION['opmerking'])) ? $_SESSION['opmerking'] : ""; ?></textarea>
</td>
</tr>
<?php if (in_array('opmerking', $_GET['error'])) { ?>
<tr>
<td colspan="2">
<font color="red">Er is geen opmerking ingevuld</font>
</td>
</tr>
<?php } ?>
<tr>
<tr>
<td colspan="2" class="verzenden">
<input name="verzenden" type="image" id="verzenden" src="img/verzenden.png" alt="Verzenden" title="Verzenden" />
</td>
</tr>
</table>
</form>
Since your using sessions to set the value in the inputs of the form you could just set those session values to nothing after the send occurs.
} else {
// send mail if (post) parameters are correct
if (mail(
'tim-luijten#hotmail.com',
'Afsprakenformulier o-vita.nl',
"Er is contact opgenomen via het afsprakenformulier. Zie onderstaande gegevens: \n\n
Naam: {$name} \n
E-mailadres: {$email} \n
Adres: {$adres} \n
Postcode: {$postcode} \n
Woonplaats: {$woonplaats} \n
Telefoonnummer: {$telefoon} \n
Datum: {$dag} - {$dag_nummer} - {$maand} \n
Tijd: {$tijd} \n
Opmerking: {$opmerking} \n"
,
"From: {$email} \r\n"
))
{
$_SESSION['name'] = "";
$_SESSION['email'] = "";
$_SESSION['adres'] = "";
$_SESSION['postcode'] = "";
$_SESSION['woonplaats'] = "";
$_SESSION['telefoon'] = "";
$_SESSION['dag'] = "";
$_SESSION['dag_nummer'] = "";
$_SESSION['maand'] = "";
$_SESSION['tijd'] = "";
$_SESSION['opmerking'] = "";
header("Location: bedankt_afspraak.php");
exit;
} else {
//display a message that the message failed to send.
}
}
Related
I have a form of 5 fields. when click on submit button it will fetch Amount against the fields from database MSSQL. Now when i fill form and submit it is giving an error. i have used MSSQL procedure query to execute it. please help me out i am in trouble now.
<div id="middle_pane">
<div>
<div id="inner_pane">
<div id="center_pane">
<div id="center_inner_pane">
<div class="txt_content">
<table width="385" height="200" style=" border:2px solid silver"
cellpadding="6px" cellspacing="0px" align="center" border="0">
<form method="POST" action="<?php bloginfo('url');?>/fedex-tariff">
<tr>
<td colspan="2" style="background:#0066FF; color:#FFFFFF;
fontsize:50px">Fedex Rate Card</td></tr>
<tr>
<td>Origin</td>
<td>
<select name="origin" id="origin" onChange="">
<option value="pakistan">Pakistan</option>
</select>
</td>
</tr>
<tr>
<td>Select Origin city </td>
<td>
<select name="city_id" id="city_id">
<option value="">--SELECT CITY--</option>
<?php
$city = "select * from branches";
$city_query = mssql_query($city);
while ($row_city = mssql_fetch_array($city_query)){
?>
<option value="<?php echo $row_city['name'];?>"> <?php echo
$row_city['name']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td>Select Destination </td>
<td>
<select name="country_id" id="country_id">
<option value="">--SELECT Destination--</option>
<?php
$service= "select * from country";
$service_query= mssql_query($service);
while ($row_service = mssql_fetch_array($service_query)){
?>
<option value="<?php echo $row_service['Name'];?>"> <?php
echo $row_service['Name']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td> Selection of Weight </td>
<td>
<div id="wgt">
<input type="text" id="weight" name="weight" value=""
placeholder="weight...." required="">
</div>
</td>
</tr>
<tr>
<td>Select Your Service</td>
<td>
<select name="service_id" id="service_id">
<option value="">--SELECT--</option>
<?php
$service_type = "SELECT distinct ServiceTypeId from
dbo.IntlZoneCountry where ServiceTypeId IN ('FedEx Cash Tariff
Docs','FedEx Box','FedEx Student Package')";
$res_type = mssql_query($service_type);
$cnt_type = mssql_num_rows($res_type);
while($row_type = mssql_fetch_array($res_type)){
?>
<option value="<?php echo $row_type['ServiceTypeId'];?>"><?php
echo $row_type['ServiceTypeId'];?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td> <input type="submit" value="Calculate" name="submit"
class="btn"></td>
</tr>
</form>
<table width="385" style=" border:2px solid silver"
cellpadding="6px" cellspacing="0px" align="center" border="0">
<tr>
<td>
<?php
if(isset($_POST['submit']))
{
$city_id = $_POST['city_id'];
$country_id = $_POST['country_id'];
$service_id = $_POST['service_id'];
$weight_id = $_POST['weight'];
if(empty($city_id) || empty($country_id) || empty($service_id) ||
empty($weight_id)){
?><center><?php echo "Please filled all the fields first.";?>
</center>
<?php
}
else{
$s = "[SP_UpdateCNPrice_Int_Tariff]
'$weight_id','$city_id','$country_id','$service_id'";
$result = mssql_query($s);
while($row = mssql_fetch_assoc($result)){
?>
</td>
</tr>
<tr style="background:#00CFFF; color:blue;">
<td>
<center>
<font size="3">
<?php
$val = $row['amount'];
$gst = $row['gst'];
echo "<strong>"."Rate : "."$".""." ".$val.$gst;
?>
</font>
</center>
</td>
</tr>
<tr style="background:#00CFFF; color:blue;">
<td><center> All Rates are Exclusive of 16% GST + 23% fuel
Charges (FSC).</center> </td>
</tr>
<?php
}
}
}
?>
</table>
</div>
</div>
</div>
</div>
</div>
MSSQL Procedure Screenshot
Front Display of Website
The error I'm having related to the drop-down list:
You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use
near '','100',' Progress ')' at line 1
<?php
session_start();
/* Database connection settings */
$host = '';
$user = '';
$pass = '';
$db = '';
$mysqli = new mysqli($host,$user,$pass,$db) or die($mysqli->error);
?>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Passport = $_POST['Passport'];
$TeachersName = $_POST['TeachersName'];
$Date = $_POST['Date'];
$CourseType = $_POST['CourseType'];
$CourseCode = $_POST['CourseCode'];
$Grammar = $_POST['Grammar'];
$Reading = $_POST['Reading'];
$Writing = $_POST['Writing'];
$Listening = $_POST['Listening'];
$Speaking = $_POST['Speaking'];
$TeachersAssessment = $_POST['TeachersAssessment'];
$Totalz = $_POST['Totalz'];
$Overallz = $_POST['Overallz'];
$Progress = $_POST['Progress'];
}
$Results = $Grammar + $Reading + $Writing + $Listening + $Speaking + $TeachersAssessment;
$Overall = $Results /130*100;
if(isset($_POST['SubmitForm']))
{
$checkBoxz= implode(",",$_POST['Progress']);
$query="INSERT INTO examresults (FirstName, LastName, Passport, TeachersName, Date, CourseType, CourseCode, Grammar, Reading, Writing, Listening, Speaking, TeachersAssessment, Totalz, Overallz, Progress) VALUES ('$FirstName','$LastName','$Passport','$TeachersName','$Date','$CourseType','$CourseCode','$Grammar','$Reading','$Writing','$Listening','$Speaking','$TeachersAssessment',$Totalz','$Overallz','". $checkBoxz ."')";
mysqli_query($mysqli,$query) or die($mysqli->error);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Exam Cover Sheet</title>
<link rel="stylesheet" href="css/jquery-ui.css">
<script src="js/jquery-1.12.4.js"></script>
<script src="js/jquery-ui.js"></script>
<script>
$( function() {
$( "#datepicker" ).datepicker();
} );
</script>
</head>
<body>
<form name="form1" method="post" action="cal.php">
<p>
<label for="textfield"></label>
</p>
<table width="63%" border="0">
<tr>
<td width="19%"><strong>First Name:</strong></td>
<td width="31%"><label for="textfield9"></label>
<input type="text" name="FirstName" id="textfield9" value="<?= isset($_POST['FirstName']) ? htmlspecialchars($_POST['FirstName']) : '' ?>"/></td>
<td width="50%"> </td>
</tr>
<tr>
<td><strong>Last Name:</strong></td>
<td><input type="text" name="LastName" id="textfield10" value="<?= isset($_POST['LastName']) ? htmlspecialchars($_POST['LastName']) : '' ?>"/></td>
<td> </td>
</tr>
<tr>
<td><strong>Passport No.:</strong></td>
<td><input type="text" name="Passport" id="textfield11" value="<?= isset($_POST['Passport']) ? htmlspecialchars($_POST['Passport']) : '' ?>"/></td>
<td> </td>
</tr>
<tr>
<td><strong>Teacher's Name:</strong></td>
<td><input type="text" name="TeachersName" id="textfield13" value="<?= isset($_POST['TeachersName']) ? htmlspecialchars($_POST['TeachersName']) : '' ?>"/></td>
<td> </td>
</tr>
<tr>
<td><strong>Date:</strong></td>
<td><input type="text" name="Date" id="datepicker" value="<?= isset($_POST['Date']) ? htmlspecialchars($_POST['Date']) : '' ?>"/></td>
<td> </td>
</tr>
<tr>
<td><strong>Course Type:</strong></td>
<td><label for="select"></label>
<select name="CourseType" id="select">
<option value="Elementary 1">Elementary 1</option>
<option value="Elementary 2" >Elementary 2</option>
<option value="Elementary 3" >Elementary 3</option>
<option value="Intermediate 1" >Intermediate 1</option>
<option value="Intermediate 2" >Intermediate 2</option>
<option value="Intermediate 3" >Intermediate 3</option>
<option value="Pre-Intermediate 1">Pre-Intermediate 1</option>
<option value="Pre-Intermediate 2" >Pre-Intermediate 2</option>
<option value="Pre-Intermediate 3" >Pre-Intermediate 3</option>
</select></td>
<td> </td>
</tr>
<tr>
<td><strong>Course Code:</strong></td>
<td><label for="select2"></label>
<select name="CourseCode" id="select2">
<option value="Elementary 1">EL1</option>
<option value="Elementary 2" >EL2</option>
<option value="Elementary 3" >EL3</option>
<option value="Intermediate 1" >I1</option>
<option value="Intermediate 2" >I2</option>
<option value="Intermediate 3" >I3</option>
<option value="Pre-Intermediate 1">PI1</option>
<option value="Pre-Intermediate 2" >PI2</option>
<option value="Pre-Intermediate 3" >PI3</option>
</select></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="19%"><p><strong>Grammar:</strong></td>
<td width="31%"><p><input type="text" name="Grammar" id="textfield" value="<?= isset($_POST['Grammar']) ? htmlspecialchars($_POST['Grammar']) : '' ?>">
<strong>/35</strong></p></td>
<td width="50%"> </td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><strong>Reading:</strong></td>
<td><p><input type="text" name="Reading" id="textfield2" value="<?= isset($_POST['Reading']) ? htmlspecialchars($_POST['Reading']) : '' ?>">
<strong>/20</strong></p></td>
<td> </td>
</tr>
<tr>
<td><strong>Writing:</strong></td>
<td><p><input type="text" name="Writing" id="textfield3" value="<?= isset($_POST['Writing']) ? htmlspecialchars($_POST['Writing']) : '' ?>">
<strong>/20</strong></p></td>
<td> </td>
</tr>
<tr>
<td><strong>Listening:</strong></td>
<td><p><input type="text" name="Listening" id="textfield4" value="<?= isset($_POST['Listening']) ? htmlspecialchars($_POST['Listening']) : '' ?>">
<strong>/20</strong></p></td>
<td> </td>
</tr>
<tr>
<td><strong>Speaking:</strong></td>
<td><p><input type="text" name="Speaking" id="textfield5" value="<?= isset($_POST['Speaking']) ? htmlspecialchars($_POST['Speaking']) : '' ?>">
<strong>/20</strong></p></td>
<td> </td>
</tr>
<tr>
<td><strong>Teacher`s assessment:</strong></td>
<td><p><input type="text" name="TeachersAssessment" id="textfield6" value="<?= isset($_POST['TeachersAssessment']) ? htmlspecialchars($_POST['TeachersAssessment']) : '' ?>">
<strong>/15</strong></p></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td></td>
<td><input type="text" name="Totalz" id="textfield7" value="<?php echo "$Results" ?>">
<strong>/130</strong></td>
<td><input type="text" name="Overallz" id="textfield8" value="<?php echo "$Overall" ?>">
<strong>%</strong></td>
</tr>
<tr>
<td><input type="submit" name="Result" id="Result" value="Calculate"></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><strong>Teacher’s recommendation:</strong></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="Progress[]" value="Repeat" id="CheckboxGroup1_0">
Repeat</label>
<br></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="Progress[]" value="Progress" id="CheckboxGroup1_1">
Progress</label>
<br></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<p>
<input type="submit" name="SubmitForm" id="SubmitForm" value="Insert Records">
</p>
</form>
</body>
</html>
An error message is showing the the query part exactly after the error spot.
So if you look at your query in this place you will see the missed quote
,$Totalz','$Overallz','". $checkBoxz ."'
To prevent any possibility of introducing such an error (let alone protection from SQL injection to which your code is severely prone), you have to use prepared statements for your queries. For which purpose PDO is much more useful than mysqli.
I just can't seem to figure out the logic to write the inputted information (contact form) to a text file within the localhost.
I am uploading all of this information on my school's server. If I please could get some help. Truly can't figure this part out.
HTML CODE:
<form action="Registered.php" method="post">
<p>
<label>First Name:</label>
<input name="fName" type="text">
</p>
<p>
<label>Last Name:</label>
<input name="lName" type="text">
</p>
<p>
<label>Address:</label>
<input name="address" type="text">
</p>
<p>
<label>State:</label>
<select name="statedropdown">
<option value="Al"> Al </option>
<option value="AK"> AK </option>
<option value="AS">AS</option>
<option value="AR">AR</option>
<option value="CA">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DE">DE</option>
<option value="DC">DC</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="HI">HI</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="IA">IA</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="ME">ME</option>
<option value="MD">MD</option>
<option value="MA">MA</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MS">MS</option>
<option value="MO">MO</option>
<option value="MT">MT</option>
<option value="NE">NE</option>
<option value="NV">NV</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NY">NY</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="UT">UT</option>
<option value="VT">VT</option>
<option value="VA">VA</option>
<option value="WA">WA</option>
<option value="WV">WV</option>
<option value="WI">WI</option>
<option value="WY">WY</option>
</select>
</p>
<p>
<label>ZIP Code:</label>
<input name="zip" required="required" placeholder="12345" type="text">
</p>
<p>
<label>Email:</label>
<input name="email" required="required" placeholder="fake#email.com" type="email">
</p>
<p>
<label>Phone Number:</label>
<input name="phone" required="required" placeholder="912-555-1234" type="text">
</p>
<p>
<input value="Submit" type="submit">
<input type="reset" value="Reset">
</p>
<p>
<td align="center"> View contacts in database </td>
</p>
<p>
<td align="center"> View contacts in file </td>
</p>
</body>
</html>
PHP CODE:
<html>
<head>
<title> Thank You </title>
</head>
<body>
<?php
$username="YYYYYYYY";
$password="XXXXXXXX";
$database="ZZZZZZZZ";
#declare variables
$fName = $_POST['fName'];
$lName = $_POST['lName'];
$address = $_POST['address'];
$statedropdown = $_POST['statedropdown'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$DOCUMENT_ROOT = $SERVER['DOCUMENT_ROOT'];
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM contacts";
$result = mysql_query($query);
$num = mysql_num_rows($result);
mysql_close();
?>
<h1 align = "center"> Thanks for Registering! </h1> <br /><br />
<p align = "center"> Your information is: </p>
<table align = "center">
<tr>
<td> First Name: </td>
<td>   </td>
<td> <?php echo $fName ?> </td>
</tr>
<tr>
<td> Last Name: </td>
<td>   </td>
<td> <?php echo $lName ?> </td>
</tr>
<tr>
<td> Address: </td>
<td>   </td>
<td> <?php echo $address ?> </td>
</tr>
<tr>
<td> State: </td>
<td>   </td>
<td> <?php echo $statedropdown ?> </td>
</tr>
<tr>
<td> Zip: </td>
<td>   </td>
<td> <?php echo $zip ?> </td>
</tr>
<tr>
<td> Telephone: </td>
<td>   </td>
<td> <?php echo $phone ?> </td>
</tr>
<tr>
<td> E-mail: </td>
<td>   </td>
<td> <?php echo $email ?> </td>
</tr>
</table>
<?php
if($_POST['saveToFile'] == 'Save to File') {
$outputstring =
"First Name: $fName
Last Name: $lName
Address: $address
State: $statedropdown
Zip: $zip
Telephone: $phone
Email: $email
-----------------------\n";
$fp = fopen("FormData.txt", 'a');
flock($fp, LOCK_EX);
fwrite($fp, $outputstring, strlen($outputstring));
flock($fp, LOCK_UN);
fclose($fp);
}
?>
<p align="center"> Return to Main Page </p>
</body>
</html>
If someone could please help me out this would be highly appreciated!
Where do you get the variable $_POST['saveToFile'] from? Shouldn't there be something like a checkbox in the form?
Are there any error messages?
I would go like this:
$outputstring =
. "First Name: $fName \n"
. "Last Name: $lName \n"
. "Address: $address \n"
. "State: $statedropdown \n"
. "Zip: $zip \n"
. "Telephone: $phone \n"
. "Email: $email \n"
. "-----------------------\n";
file_put_contents("FormData.txt", $outputstring, FILE_APPEND | LOCK_EX);
The function file_put_contents opens and locks the file, appends the data to it, unlocks and finally closes it. So the only difference is the better overview.
I moved website from to other hosting server and contact form doesn't work. Current version of php is 5.2 and before was older. I saw on forums that in order for older php code to work i should turn globals on which I did (I know it's insecure and I will replace that code completely, but right now I have to make it work). Before I turned globals on nothing was working and now I'm getting message if some field is missing but nothing more than that. Any suggestions how to make this contact form work? Any answer will be very appreciated.
<?
$contact = 'contact';
require('inc_meta.php');
if($form)
{
$error = Array();
if(!trim($c_name)){ $error[sizeof($error)] = "Name"; }
if(!trim($email)){ $error[sizeof($error)] = "E-mail Address"; }
else {
if(!eregi("^[_\.0-9a-z-]+#([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$email)){ $error[sizeof($error)] = "'" . $email . "' is not avalid E-mail Address."; }
}
}
$filePath = getenv("SCRIPT_NAME");
if($_SERVER['HTTP_REFERER'] == 'http://'.$_SERVER['SERVER_NAME'].''.$filePath.'')
{
if($form && !$error)
{
$contents = "Name: $c_name\r
Address:\r
$c_address\r
$c_city, $c_state $c_zip\n
Phone: $c_phone\r
Fax: $c_fax\r
Email: $email\n
Comments or Questions:\r
$c_comments";
mail("$EMAILADMIN","email from $c_name","$contents","From: $c_name<$email>");
$status = "Thank You, <b>$c_name</b><br><br>";
$status .= "Your e-mail message has been sent. We will contact you shortly about your inquiry. ";
$status .= "If you need more assistance or have questions, please call us at <b>1234567</b><br><br>";
$status .= "Thank You,<br><b>Owner</b><br>";
}}
?>
<table width="860" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<td width="325">
<? include('inc_sideBar.php'); ?>
</td>
<td width="535">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<? include('inc_header.php'); ?>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td align="center" valign="top">
<? if(!$status){ ?>
<br>
<table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<form name="form" method="post" action="<? echo $PHP_SELF; ?>">
<td>
<? if(sizeof($error)){ ?>
<font color="#FADE82"><b> The following fields are still
required:<br>
<?
for($i = 0; $i < sizeof($error); $i++) {
echo " *", " ", $error[$i];
}
?>
</b></font><br>
<br>
<? } ?>
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="54%" valign="top"><font color="#FFF9DD">Name</font><font color="#CC0000">
<font color="#FADE82"></font></font><b><font color="#CC0000"><font color="#FADE82">*</font><br>
<input type="text" name="c_name" value="<? echo $c_name; ?>" size="23">
</font></b></td>
<td width="46%" valign="top"><font color="#FFF9DD">State</font><b><br>
</b>
<select name="c_state">
<option>
<? echo $c_state; ?>
</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="DC">Washington, D.C.</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</td>
</tr>
<tr>
<td valign="top" width="54%"><font color="#FFF9DD">E-mail</font><font color="#CC0000">
<font color="#FADE82"></font></font><b><font color="#CC0000"><font color="#FADE82">*</font>
<br>
<input type="text" name="email" value="<? echo $email; ?>" size="23">
</font></b></td>
<td valign="top" width="46%"><font color="#FFF9DD">Zip</font><b><br>
</b>
<input type="text" name="c_zip" value="<? echo $c_zip; ?>" size="20">
</td>
</tr>
<tr>
<td valign="top" width="54%"><font color="#FFF9DD">Address</font><b><br>
<input type="text" name="c_address" value="<? echo $c_address; ?>" size="23">
</b></td>
<td valign="top" width="46%"><font color="#FFF9DD">Phone</font><b><br>
</b>
<input type="text" name="c_phone" value="<? echo $c_phone; ?>" size="20">
</td>
</tr>
<tr>
<td valign="top" width="54%"><font color="#FFF9DD">City</font><b><br>
<input type="text" name="c_city" value="<? echo $c_city; ?>" size="23">
</b></td>
<td valign="top" width="46%"><font color="#FFF9DD">Fax</font><b><br>
</b>
<input type="text" name="c_fax" value="<? echo $c_fax; ?>" size="20">
</td>
</tr>
<tr>
<td valign="top" width="54%"> </td>
<td valign="top" width="46%"> </td>
</tr>
<tr>
<td valign="top" colspan="2"> <font color="#FFF9DD">Comments
or Questions?:</font><br>
<textarea name="c_comments" wrap="VIRTUAL" cols="30" rows="5"><? echo $c_comments; ?></textarea>
<br>
<br>
</td>
</tr>
<tr>
<td valign="top" colspan="2">
<input type="image" border="0" name="imageField" src="images/submit.gif" class="select">
</td>
</tr>
</table>
<input type="hidden" name="form" value="one">
</td>
</form>
</tr>
</table>
<? }else{ ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> <br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<font color="#FFF9DD"><? echo $status; ?></font>
</td>
</tr>
</table>
</td>
</tr>
</table>
<? } ?>
</td>
</tr>
</table>
<br>
<? include('footer_info.php'); ?>
</td>
</tr>
</table>
</td>
</tr>
</table>
<? require('inc_footer.php'); ?>
You should access the form data using the $_POST array.
Read the Warning in this page of the php docs: http://www.php.net/manual/en/language.variables.predefined.php
please see the following code
// redirect to success page
if ($success){
header( 'Location: ../Scripts/_lib/phpmailer-fe.php');
}
else{
print "<meta http-equiv="refresh" content="0;URL=error.html">";
}
its not working
<form method="post" action="" enctype="multipart/form-data" name="quest">
<input type="hidden" value="valvedevelopertool.html" name="referer">
<table cellspacing="0" cellpadding="0"width="650" align="center">
<tr class="tablerow">
<td id="apptitlebox" colspan="2"><span class="valvedevelopertitle">Valve Specification Developer Tool</span></td></tr>
</table>
<br /><br />
<p align="center">Please enter known details to help assist us in processing your enquiry accuratly and quickly.</p>
<table cellspacing="0" cellpadding="0" width="650" align="center" class="tablecontainer">
<tr>
<td class="valvedevelopertoolreftitle">Reference</td><td><input type="text" style="width:204px" class="border" name="vdt_ref"/></td><td class="valvedevelopertoolreftitle">Date</td><td><input type="text" style="width:204px" class="border" name="vdt_date"/></td>
</tr>
</table>
<br />
<table cellspacing="0" cellpadding="0" width="650" align="center" class="tablecontainer">
<tr><td class="valvedevelopertoolreftitle">Enquiry 1</td></tr>
<tr class="tablerow">
<td width="154" class="titlebg"></td><td width="243" class="valvedevelopertooltexttitle titlebg">Select Known Specifications</td><td width="99" class="valvedevelopertooltexttitle titlebg"></td>
<td width="252" class="valvedevelopertooltexttitle titlebg">Add More Detail</td>
</tr>
<tr class="tablerow">
<td class="valvedevelopertoolleft">Qty</td>
<td class="valvedevelopertooltext">
<select name="vdt_qty" id="Type" class="border" style="width:204px" onchange="qty1(document.quest.vdt_qty.value); qty2(document.quest.vdt_qty.value)">
<option selected value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="otherqty">Other (specify to the right)</option>
</select>
</td>
<td class="valvedevelopertoolextratext"><span id="otherqtytitle" class="border"></span></td>
<td class="valvedevelopertooltext"><span id="otherqty" class="border"></span>
</td>
</tr>
<tr class="tablerow">
<td class="valvedevelopertoolleft highlight1">Type</td>
<td class="valvedevelopertooltext highlight1">
<select name="vdt_type" id="vdt_type" class="border" style="width:204px" onchange="type1(document.quest.vdt_type.value); type2(document.quest.vdt_type.value)">
<option selected value="">Please Select</option>
<option value="PSV">PSV (Pressure Safety/Relief Valve)</option>
<option value="Controll Valve">Control Valve</option>
<option value="Ball Valve">Ball Valve</option>
<option value="Wedge Gate Valve">Wedge Gate Valve</option>
<option value="Parallel Slide Gate Valve">Parallel Slide Gate Valve</option>
<option value="Through Conduit Gate Valve">Through Conduit Gate Valve</option>
<option value="Knife Gate Valve">Knife Gate Valve</option>
<option value="Globe Valve">Globe Valve</option>
<option value="checkvalve">Check Valve</option>
<option value="Plug Valve">Plug Valve</option>
<option value="Choke Valve">Choke Valve</option>
<option value="Butterfly Valve">Butterfly Valve</option>
<option value="Needle Valve">Needle Valve</option>
<option value="Double Block/Bleed Valve">Double Block / Bleed Valve</option>
<option value="3 Way Valve">3 Way Valve</option>
<option value="4 Way Valve">4 Way Valve</option>
</select></td>
<td class="valvedevelopertoolextratext highlight1"><span id="checkvalvetypetitle" class="border"></span></td>
<td class="valvedevelopertooltext highlight1"><span id="checkvalvetype" class="border"></span></td>
</tr>
<tr class="tablerow">
<td class="valvedevelopertoolleft">Size</td>
<td class="valvedevelopertooltext">
<select name="vdt_size" id="Type" class="border" style="width:204px" onchange="size1(document.quest.vdt_size.value); size2(document.quest.vdt_size.value)">
<option selected value="">Please Select</option>
<option value="0.5">0.5"</option>
<option value="1">1"</option>
<option value="1.5">1.5"</option>
<option value="2">2"</option>
<option value="4">4"</option>
<option value="6">6"</option>
<option value="8">8"</option>
<option value="10">10"</option>
<option value="12">12"</option>
<option value="14">14"</option>
<option value="16">16"</option>
<option value="18">18"</option>
<option value="20">20"</option>
<option value="24">24"</option>
<option value="30">30"</option>
<option value="36">36"</option>
<option value="40">40"</option>
<option value="othersize">Other (specify to the right)</option>
</select>
</td>
<td class="valvedevelopertoolextratext"><span id="othersizetitle" class="border"></span></td>
<td class="valvedevelopertooltext"><span id="othersize" class="border"></span></td>
</tr>
<tr class="tablerow">
<td class="valvedevelopertoolleft highlight1">Pressure Class</td>
<td class="valvedevelopertooltext highlight1">
<select name="vdt_class" onchange="class1(document.quest.vdt_class.value); class2(document.quest.vdt_class.value)" class="border" style="width:204px">
<option value="">Please Select</option>
<option value="ANSI">ANSI</option>
<option value="PN">PN</option>
<option value="API">API</option>
</select>
</td>
<td class="valvedevelopertoolextratext highlight1" align="right"><span id="classname" class="border"></span></td>
<td class="valvedevelopertooltext highlight1"><span id="classtypes" class="border"></span></td>
</tr>
<tr class="tablerow">
<td class="valvedevelopertoolleft">End Connections</td>
<td class="valvedevelopertooltext">
<select name="vdt_end" id="Type" class="border" style="width:204px">
<option selected value="">Please Select</option>
<option value="Flanged Raised Face">Flanged Raised Face</option>
<option value="Flanged Flat Face">Flanged Flat Face</option>
<option value="Flanged Ring Type Joint">Flanged Ring Type Joint</option>
<option value="Socket Weld Female">Socket Weld Female</option>
<option value="Socket Weld Male">Socket Weld Male</option>
<option value="Screwed Female">Screwed Female</option>
<option value="Screwed Male">Screwed Male</option>
</select>
</td>
<td class="valvedevelopertooltext"> </td>
<td class="valvedevelopertooltext"> </td>
</tr>
<tr class="tablerow">
<td class="valvedevelopertoolleft highlight1">Bore</td>
<td class="valvedevelopertooltext highlight1">
<select name="vdt_bore" id="Type" class="border" style="width:204px">
<option selected value="">Please Select</option>
<option value="Full">Full</option>
<option value="Reduced">Reduced</option>
</select>
</td>
<td class="valvedevelopertooltext highlight1"> </td>
<td class="valvedevelopertooltext highlight1"> </td>
</tr>
<tr class="tablerow">
<td class="valvedevelopertoolleft">Body Material</td>
<td class="valvedevelopertooltext">
<select name="vdt_body" id="Type" class="border" style="width:204px" onchange="body1(document.quest.vdt_body.value); body2(document.quest.vdt_body.value)">
<option selected value="">Please Select</option>
<option value="Carbon Steel">Carbon Steel</option>
<option value="Stainless Steel">Stainless Steel</option>
<option value="Duplex">Duplex</option>
<option value="Alloy">Alloy</option>
<option value="Bronzes">Bronzes</option>
<option value="Leaded Gunmetal">Leaded Gunmetal</option>
<option value="Low Temp Nickel Alloy Steel">Low Temp Nickel Alloy Steel</option>
<option value="Titanium">Titanium</option>
<option value="Hastelloy">Hastelloy</option>
<option value="Monel">Monel</option>
<option value="Cast Iron">Cast Iron</option>
</select>
</td>
<td class="valvedevelopertoolextratext"><span id="bodytitle" class="border"></span></td>
<td class="valvedevelopertooltext"><span id="bodytypes" class="border"></span></td>
</tr>
<tr class="tablerow">
<td class="valvedevelopertoolleft highlight1">Trim Material</td>
<td class="valvedevelopertooltext highlight1">
<select name="vdt_trim" id="Type" class="border" style="width:204px" onchange="trim1(document.quest.vdt_trim.value); trim2(document.quest.vdt_trim.value)">
<option selected value="">Please Select</option>
<option value="Carbon Steel">Carbon Steel</option>
<option value="Stainless Steel">Stainless Steel</option>
<option value="Duplex">Duplex</option>
<option value="Alloy">Alloy</option>
<option value="13% Chrome Steel">13% Chrome Steel</option>
<option value="Bronze and Aluminium Bronze">Bronze & Aluminium Bronze</option>
<option value="Nickel Aluminium Bronze">Nickel Aluminium Bronze</option>
<option value="Leaded Gunmetal">Leaded Gunmetal</option>
<option value="Titanium">Titanium</option>
<option value="Low Temp Nickel Alloy Steel">Low Temp Nickel Alloy Steel</option>
<option value="Monel">Monel</option>
<option value="Cast Iron">Cast Iron</option>
<option value="Ceramics">Ceramics</option>
</select>
</td>
<td class="valvedevelopertoolextratext highlight1"><span id="trimtitle" class="border"></span></td>
<td class="valvedevelopertooltext highlight1"><span id="trimtypes" class="border"></span></td>
</tr>
<tr class="tablerow">
<td class="valvedevelopertoolleft">Seat Material</td>
<td class="valvedevelopertooltext">
<select name="vdt_seat" id="Type" class="border" style="width:204px" onchange="seat1(document.quest.vdt_seat.value); seat2(document.quest.vdt_seat.value)">
<option selected value="">Please Select</option>
<option value="PTFE">PTFE</option>
<option value="Nylon">Nylon</option>
<option value="Peek">Peek</option>
<option value="Viton">Viton</option>
<option value="Metal">Metal</option>
</select>
</td>
<td class="valvedevelopertoolextratext" align="right"><span id="seatgradetitle" class="border"></span></td>
<td class="valvedevelopertooltext"><span id="seatgrade" class="border"></span></td>
</tr>
<tr class="tablerow">
<td class="valvedevelopertoolleft highlight1">NACE Materials</td>
<td class="valvedevelopertooltext highlight1">
<select name="vdt_nace" id="Type" class="border" style="width:204px">
<option selected value="">Please Select</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</td>
<td class="valvedevelopertooltext highlight1"> </td>
<td class="valvedevelopertooltext highlight1"> </td>
</tr>
<tr class="tablerow">
<td class="valvedevelopertoolleft">Operation</td>
<td class="valvedevelopertooltext">
<select name="vdt_operation" id="Type" class="border" style="width:204px" onchange="operation1(document.quest.vdt_operation.value); operation2(document.quest.vdt_operation.value)">
<option selected value="">Please Select</option>
<option value="Manual Hand Lever">Manual Hand Lever</option>
<option value="Manual Handwheel">Manual Handwheel</option>
<option value="Manual Gearbox">Manual Gearbox</option>
<option value="Automated/Actuated">Automated / Actuated</option>
<option value="otheroperation">Other (specify to the right)</option>
</select>
</td>
<td class="valvedevelopertoolextratext"><span id="otheroperationtitle" class="border"></span></td>
<td class="valvedevelopertooltext"><span id="otheroperation" class="border"></span>
</td>
</tr>
<tr>
<td class="valvedevelopertoolleft highlight1">Other Information</td>
<td class="valvedevelopertooltextarea highlight1" colspan="3" align="left" style="padding-left:23px; padding-top:3px; height:95px"><span class="valvedevelopertooltextarea highlight1" style="padding-top:3px; height:95px">
<textarea name="textarea" cols="5" rows="4" class="border" style="width:550px"></textarea>
</span></td>
</tr>
</table>
<br />
<table cellspacing="0" cellpadding="0" width="650" align="center" class="tablecontainer">
<tr class="tablerow">
<td width="154" class="titlebg"></td><td width="243" class="valvedevelopertooltexttitle titlebg">Your Details</td><td width="99" class="valvedevelopertooltexttitle titlebg"></td>
<td width="252" class="valvedevelopertooltexttitle titlebg"></td>
</tr>
<tr>
<td class="valvedevelopertoolleft" width="154">Name</td>
<td class="valvedevelopertooltext" width="243"><input name="contact_name" style=" width: 200px;" type="text" maxlength="200" class="border"></td>
<td class="valvedevelopertoolextratext" width="99"> </td>
<td class="valvedevelopertooltext" width="252"> </td>
</tr>
<tr>
<td class="valvedevelopertoolleft highlight1" width="154">Email Address</td>
<td class="valvedevelopertooltext highlight1" width="243"><input name="contact_email" style=" width: 200px;" type="text" maxlength="200" class="border"></td>
<td class="valvedevelopertoolextratext highlight1" width="99"> </td>
<td class="valvedevelopertooltext highlight1" width="252"> </td>
</tr>
<tr>
<td class="valvedevelopertoolleft" width="154">Telephone Number</td>
<td class="valvedevelopertooltext" width="243"><input name="contact_tel" style=" width: 200px;" type="text" maxlength="200" class="border"></td>
<td class="valvedevelopertoolextratext" width="99"> </td>
<td class="valvedevelopertooltext" width="252"> </td>
</tr>
<tr>
<td class="valvedevelopertoolleft highlight1" width="154">Company</td>
<td class="valvedevelopertooltext highlight1" width="243"><input name="contact_company" style=" width: 200px;" type="text" maxlength="200" class="border"></td>
<td class="valvedevelopertoolextratext highlight1" width="99"> </td>
<td class="valvedevelopertooltext highlight1" width="252"> </td>
</tr>
</table>
<br />
<table cellspacing="0" cellpadding="0" width="650" align="center" class="tablecontainer">
<tr>
<td colspan="4">
<?php
# Get the reCAPTCHA library
require_once('../recaptcha/recaptchalib.php');
# These are /not/ real keys - you must replace them with your *own* keys
# obtained from http://recaptcha.net/api/getkey
define('PUBLIC_KEY', '[MY PUBLIC KEY]');
define('PRIVATE_KEY', '[MY PRIVATE KEY]');
# Did the user fail the captcha test?
$error = null;
# This is where we process the user's response. We don't
# do this when the form is initially displayed - only
# when the user submits it.
if ($_POST["recaptcha_response_field"]) {
$response = recaptcha_check_answer(
PRIVATE_KEY, $_SERVER['REMOTE_ADDR'],
$_POST['recaptcha_challenge_field'],
$_POST['recaptcha_response_field']
);
if ( $response->is_valid ) {
// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['vdt_type']));
$EmailTo = "MAIL#MAIL.COM";
// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
print '<meta http-equiv="refresh" content="0;URL=error.html">';
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "n";
$Body .= "n";
$Body .= "Email: ";
$Body .= $EmailFrom;
$Body .= "n";
$Body .= "n";
$Body .= "Company: ";
$Body .= $Company;
$Body .= "n";
$Body .= "n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "n";
$Body .= "n";
$Body .= "Fax: ";
$Body .= $Fax;
$Body .= "n";
$Body .= "n";
$Body .= "Location: ";
$Body .= $Location;
$Body .= "n";
$Body .= "n";
$Body .= "How Did You Hear About Us: ";
$Body .= $HowDidYouHearAboutUs;
$Body .= "n";
$Body .= "n";
$Body .= "Enquiry Type: ";
$Body .= $EnquiryType;
$Body .= "n";
$Body .= "n";
$Body .= "Comments: ";
$Body .= $Comments;
$Body .= "n";
$Body .= "n";
$Body .= "Join Mailing List: ";
$Body .= $MailingList;
$Body .= "n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: noreply#score-training.com");
// redirect to success page
if ($success){
if (isset($_POST['submit'])) {
header ("Location: ../Scripts/_lib/phpmailer-fe.php");
}
else{
print '<meta http-equiv="refresh" content="0;URL=error.html">';
}
}
# For example
# ... validate user input ...
# ... store form data in a database ...
# ... redirect to 'thank you' page
}
else {
# The user failed the reCAPTCHA test so we need
# to fill in the error message and re-try the
# form submission
$error = $response->error;
}
}
# Display the reCAPTCHA challenge. The first time
# through $error will be null.
echo recaptcha_get_html( PUBLIC_KEY, $error );
?>
</td></tr>
<tr>
<td colspan="4" align="center"><input type="submit" value="Submit Enquiry" class="border" name="submit"> <input type="reset" value="Clear Form" class="border"></td>
</tr>
</table>
</form>
You are quoting your string in a wrong way. Encapsulate it in single quotes:
print '<meta http-equiv="refresh" content="0;URL=error.html">';
You should be able to find such errors with any editor that provides decent syntax highlighting (it can even be seen with the syntax highlighter in your question).
I don't know whether this solves the problem, you don't give enough information.
Also note that according to Wikipedia, this method of refreshing is deprecated.
If you are using HTTP 1.1, the URL provided to Location must be absolute:
Note: HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself.