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.
Related
My insert statement does nothing when i try and submit the form its supposed to show the conformation message but nothing shows up at all and it doesnt submit into the database.
And for reference there is no error code that shows up when i click submit its just that nothing happens.
<?php require_once('dbuser.php');?>
<?php
// if the submit button has been selected
if(isset($_POST['submit_registration'])) {
// assign variable to each for control to capture the values
$first = $_POST['first_name'];
$last = $_POST['last_name'];
$email = $_POST['email'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$postal = $_POST['postal_code'];
$phone = $_POST['phone'];
$distance = $_POST['dist'];
//assign null values for use with the isset function to identify null fields that are missing a value
$nofirst = null;
$nolast = null;
$noemail = null;
$noaddress1 = null;
$noaddress2 = '';
$nocity = null;
$nostate= null;
$nopostal = null;
$nophone = null;
$nodistance = null;
// if value of variable is nothing assign something other than null
if($first=="") {
$nofirst = '';
$novalue = '';
}
if($last==""){
$nolast = '';
$novalue ='';
}
if($email=="") {
$noemail = '';
$novalue = '';
}
if($address1=="") {
$noaddress1 = '';
$novalue = '';
}
if($address2=="") {
$noaddress2 = '';
$novalue = '';
}
if($city=="") {
$nocity = '';
$novalue = '';
}
if($state=="") {
$nostate = '';
$novalue = '';
}
if($postal=="") {
$nopostal = '';
$novalue = '';
}
if($phone=="") {
$nophone = '';
$novalue = '';
}
if($distance=="") {
$nodistance = '';
$novalue = '';
}
if(isset($novalue)) {$confim = 'Please enter all values';}
else {
$insertsql = "INSERT INTO `runner`(`fname`, `lname`,`email`,`address1`,`address2`,`city`,`state`,`postalcode`, `phone`, `distance`) VALUES ('$first', '$last', '$email', '$address1','$address2','$city','$state','$postal','$phone','$distance')";
mysql_query($connect, $insertsql) or die ("Insert failed: ".mysql_error($connect));
$confirm = 'Thank you for registering!';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Matthew Cromika Website</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<header><img src="images/eastersealsclevelogo.png" alt="Easter Seals Logo" width="445" height="300"</img> </header>
<nav>
<ul>
<li>Home</li>
<li>Run Sign-Up</li>
<li>Refer-a-Friend</li>
</ul>
</nav>
<h1>Sign up for a event!</h1>
<p>If you would like to join in any of the runs, then feel free to sign up using the form provided below.</p><br>
<?php {echo $confirm;} ?>
<form method="post" action="signup.php">
<form name="signup" title="signup" id="signup">
<table>
<tr>
<td><label for="first_name">First Name:</label></td>
<td><input type="text" name="first_name" id="first_name" title="first name" ></td>
<?php if(isset($nofirst)){echo"<span class='errormsg'> First name is required<br></span>";}?>
</tr>
<tr>
<td><label for="last_name">Last Name:</label></td>
<td><input type="text" name="last_name" id="last_name" title="last name" ></td>
<?php if(isset($nolast)){echo"<span class='errormsg'> Last Name is required<br></span>";}?>
</tr>
<tr>
<td><label for="email">Email:</label></td>
<td><input type="email" name="email" id="email" title="email" ></td>
<?php if(isset($noemail)){echo"<span class='errormsg'> Your Email is required<br></span>";}?>
</tr>
<tr>
<td><label for="address1">Address 1:</label></td>
<td><input type="text" name="address1" id="address1" title="address1" ></td>
<?php if(isset($noaddress1)) {echo"<span class='errormsg'> Your Address is required<br></span>";}?>
</tr>
<tr>
<td><label for="address2">Address 2:</label></td>
<td><input type="text" name="address2" id="address2" title="address2"></td>
</tr>
<tr>
<td><label for="city">City:</label></td>
<td><input type="text" name="city" id="city" title="city" value="Cleveland" ></td>
<?php if(isset($nocity)){echo"<span class='errormsg'> Your City is required<br> </span>";}?>
</tr>
<tr>
<td><label for="state">State:</label></td>
<td>
<select required name="state">
<option value="state" name="state" title="state">Select A Option</option>>
<option value="AL" name="AL" title="alabama">Alabama</option>
<option value="AK" name="AK" title="alaska">Alaska</option>
<option value="AZ" name="AZ" title="arizona">Arizona</option>
<option value="AR" name="AR" title="arkansas">Arkansas</option>
<option value="CA" name="CA" title="california">California</option>
<option value="CO" name="CO" title="colorado">Colorado</option>
<option value="CT" name="CT" title="connecticut">Connecticut</option>
<option value="DE" name="DE" title="delware">Delaware</option>
<option value="DC" name="DC" title="district of columbia">District Of Columbia</option>
<option value="FL" name="FL" title="florida">Florida</option>
<option value="GA" name="GA" title="georgia">Georgia</option>
<option value="HI" name="HI" title="hawaii">Hawaii</option>
<option value="ID" name="ID" title="idaho">Idaho</option>
<option value="IL" name="IL" title="illinois">Illinois</option>
<option value="IN" name="IN" title="indiana">Indiana</option>
<option value="IA" name="IA" title="iowa">Iowa</option>
<option value="KS" name="KA" title="kansas">Kansas</option>
<option value="KY" name="KY" title="kentucky">Kentucky</option>
<option value="LA" name="LA" title="louisiana">Louisiana</option>
<option value="ME" name="ME" title="maine">Maine</option>
<option value="MD" name="MD" title="maryland">Maryland</option>
<option value="MA" name="MA" title="massachusetts">Massachusetts</option>
<option value="MI" name="MI" title="michigan">Michigan</option>
<option value="MN" name="MN" title="minnesota">Minnesota</option>
<option value="MS" name="MS" title="mississippi">Mississippi</option>
<option value="MO" name="MO" title="missouri">Missouri</option>
<option value="MT" name="MT" title="montana">Montana</option>
<option value="NE" name="NE" title="nebraska">Nebraska</option>
<option value="NV" name="NV" title="nevada">Nevada</option>
<option value="NH" name="NH" title="new hampshire">New Hampshire</option>
<option value="NJ" name="NJ" title="new jersey">New Jersey</option>
<option value="NM" name="NM" title="new mexico">New Mexico</option>
<option value="NY" name="NY" title="new york">New York</option>
<option value="NC" name="NC" title="north carolina">North Carolina</option>
<option value="ND" name="ND" title="north dakota">North Dakota</option>
<option value="OH" name="OH" title="ohio" selected>Ohio</option>
<option value="OK" name="OK" title="oklahoma">Oklahoma</option>
<option value="OR" name="OR" title="oregon">Oregon</option>
<option value="PA" name="PA" title="pennsylvania">Pennsylvania</option>
<option value="RI" name="RI" title="rhode island">Rhode Island</option>
<option value="SC" name="SC" title="south carolina">South Carolina</option>
<option value="SD" name="SD" title="south dakota">South Dakota</option>
<option value="TN" name="TN" title="tennessee">Tennessee</option>
<option value="TX" name="TX" title="texas">Texas</option>
<option value="UT" name="UT" title="utah">Utah</option>
<option value="VT" name="VT" title="vermont">Vermont</option>
<option value="VA" name="VA" title="virginia">Virginia</option>
<option value="WA" name="WA" title="washington">Washington</option>
<option value="WV" name="WV" title="west virginia">West Virginia</option>
<option value="WI" name="WI" title="wisconsin">Wisconsin</option>
<option value="WY" name="WY" title="wyoming">Wyoming</option>
</select></td>
<?php if(isset($nostate)) {echo "<span class='errormsg'>Your state is required<br></span>";}?>
</tr>
<tr>
<td><label for="postal_code">Zip Code:</label></td>
<td><input type="text" name="postal_code" id="postal_code" title="postal_code" pattern="[\d]{5}(-[\d]{4})" ></td>
<?php if(isset($nopostal)) {echo "<span class='errormsg'> Your postal code is required<br></span>";}?>
</tr>
<tr>
<td><label for="phone">Phone:</label></td>
<td><input type="tel" name="phone" id="phone" title="phone" ></td>
<?php if(isset($nophone)) {echo "<span class='errormsg'> Your Phone number is required<br></span>";}?>
</tr>
<tr>
<td><label for="distance">Distance:</label></td><br>
<td><input type="radio" name="dist" value="1mile" id="dist" title="1mile" checked ><label>1 Mile</label><br>
<input type="radio" name="dist" value="5k" id="dist" title="5k"><label>5K</label><br>
<input type="radio" name="dist" value="10k" id="dist" title="10k"><label>10K</label></td>
<?php if(isset($nodist)) {echo "<span class='errormsg'> You must choose a distance</span>";}?>
</tr>
<tr>
<td> <input type="submit" name="submit_registration" id="submit_registration" title="submit" value="Submit Form"></td>
<td> <input type="button" name="cancel" id="cancel" title="cancel" value="Cancel" onClick="location.href='index.html'"></td>
</tr>
</table>
</form>
<p>If you would like to invite a friend then click here and have them join in!
</p>
</body>
</html>
Any help you can provide is greatly appreciated.
For some reason every once in a while my code will enter data into the database twice. I have changed my code and made some tweaks but have not had any luck. I know I must be over looking something I just don't know what.
<?php
$con = new mysqli("localhost", "******", "******", "******");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$conpo = new mysqli("localhost", "******", "******", "******");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$resultpo = mysqli_query($conpo, "SELECT * FROM fpo ORDER BY ponum DESC LIMIT 1");
while ($rowp = mysqli_fetch_array($resultpo)) {
$po = $rowp['ponum'];
$ponum = ++$po;
}
$date = $_POST['date'];
$to = $_POST['to'];
$time = $_POST['time'];
$vin = $_POST['stk_vin'];
$reason = $_POST['reason'];
$amount = $_POST['amount'];
$empnum = $_POST['emp'];
$mananger = $_POST['mananger'];
$accnum = $_POST['acc'];
$store_location = $_POST['store'];
$borr = $_POST['borrowed'];
$oldid = $_POST['oldid'];
mysqli_query($con,
"INSERT INTO fpo (" .
"`ponum`, `date`, `to`, `time`, `vin`, `reason`, `amount`, `empnum`, `mananger`, `accnum`, `store_location`, `borr`" .
") VALUES (" .
"'$ponum', '$date', '$to', '$time', '$vin', '$reason', '$amount', '$empnum', '$mananger', '$accnum', '$store_location', '$borr'" .
")");
?>
Here is the html forum page.
<form action="print.php" method="POST" name="form1" id="form1">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" class="table" style="width:700px">
<tbody>
<tr>
<td height="19" colspan="2" valign="middle" class="to" style="width:450px" ><div class="logo"></div></td>
<td width="95" rowspan="2" valign="bottom"><div class="date">Date:
<label>
<input name="date" type="text" readonly id="date" value="07/15/2015" size="10" />
</label>
</div></td>
<td width="106" rowspan="2" valign="bottom" class="po" style="width:100px" ><div class="date">PO: <span id="sprytextfield3">
<label>
<input name="po" readonly type="text" value="14739" />
<input type="hidden" name="oldid" value="11810">
</label>
<span class="textfieldRequiredMsg">A value is required.</span></span></div></td>
</tr>
<tr>
<td height="20" colspan="2" valign="middle" class="to" style="width:450px" ><div class="toheader">To: <span id="spryselect1">
<label>
<select name="to" id="to">
<option selected="selected" disabled="disabled">Select One</option>
<option value="1">Kum-N-Go</option>
</select>
</label>
<span class="selectRequiredMsg">Please select an item.</span></span>
<input name="time" type="hidden" id="time" value="
11:13:33 ">
</div></td>
</tr>
<tr>
<td colspan="2" style="height:125px" ><b> Reason For Gas Ticket: </b> <br>
<span id="spryselect2">
<label>
<select name="reason" id="reason">
<option selected="selected" disabled="disabled">Select One</option>
<option value="Advertising">Advertising</option>
<option value="Auction">Auction</option>
</select>
</label>
<span class="selectRequiredMsg">Required</span></span><br>
<br>
Car Borrowed From Another Dealership? <br>
<span id="spryselect3">
<label>
<select name="borrowed" id="borrowed">
<option selected="selected" disabled="disabled">Select One</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</label>
<span class="selectRequiredMsg">Please select an item.</span></span><br></td>
<td><b>stk/vin/RO#:</b><br>
<span id="sprytextfield2">
<label>
<input name="stk_vin" type="text" id="stk_vin" onclick="return stk()" size="12" />
</label>
<span class="textfieldRequiredMsg"><br />
Stock or Vin .</span></span></td>
<td align="center"><b> Amount<br>
<div class="money"><span id="spryselect5">
<label><b>
<select name="amount" id="amount">
<option value="5.00" selected="selected">5.00</option>
<option value="1.00">1.00</option>
<option value="2.00">2.00</option>
<option value="3.00">3.00</option>
<option value="4.00">4.00</option>
<option value="5.00">5.00</option>
<option value="6.00">6.00</option>
<option value="7.00">7.00</option>
<option value="8.00">8.00</option>
<option value="9.00">9.00</option>
<option value="10.00">10.00</option>
</select>
</b></label>
<span class="selectRequiredMsg">Please select an item.</span></span></div>
</b></td>
</tr>
<tr>
<td width="257">Employee Requesting Po:<span id="spryselect9">
<label>
<select name="emp" id="acc">
<option selected="selected" disabled="disabled">Select One</option>
<option value="5223">5223</option>
</optgroup>
</select>
</label>
<span class="textfieldRequiredMsg">Required</span><span class="textfieldInvalidFormatMsg">Required</span></span></td>
<td width="219">Acc #:<span id="spryselect4">
<label>
<select name="acc" id="acc">
<option selected="selected" disabled="disabled">Select One</option>
<option value="51">Sales</option>
<option value="52">Services</option>
<option value="53">Parts</option>
<option value="FI">F&I</option>
</select>
</label>
<span class="selectRequiredMsg">Required</span></span></td>
<td colspan="2" align="right"><label> Mananger:
<input name="mananger" onclick="return getfoc()" type="text" id="mananger" size="12" readonly />
</label></td>
</tr>
<tr>
<td></td>
<td>Store: <span id="spryselect6">
<label>
<select name="store" id="store">
<option disabled="disabled" selected="selected">Select One</option>
<option value="chevy">Chevy</option>
<option value="Ford">Ford</option>
<option value="Dodge">Dodge</option>
</select>
</label>
<span class="selectRequiredMsg">Required</span></span></td>
<td colspan="2" align="right"><div id="btn"> </div>
<script language='javascript' type='text/javascript'>
function GetValueFromChild(myVal)
{
document.getElementById('mananger').value = myVal;
document.getElementById('btn').innerHTML = '<input type="submit" id="register" value="Print Ticket" />';
}
</script></td>
</tr>
</tbody>
</table>
<p> </p>
</form>
Because you are not doing atomic operation. Lets assume the below flow:
SELECT1 -> SELECT2-> INSERT1-> INSERT2
How are avoid this - no synchronization or locking. You can avoid this with few options.
Use a lock before entering this block and free once insert is done( in PHP). This can be based on file lock or memcache lock
You can add an index on the column you want to keep unique say, (ponum, from, to). Instead of using INSERT, you can use INSERT IGNORE
I am pretty sure your users are clicking the submit button twice I had this issue before I fixed it using jquery's validator such as following.
$(document).ready(function(){
$("#form1").validate({submitHandler: function(form) {if (!this.beenSubmitted) {this.beenSubmitted = true;form.submit();} }});
});
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
I have a script that I am writing and I have encounted a problem. I can not get the information from a dropbox to submit into a MySQL database.
Everything will show up in the database except for the item from the dropbox.
Here is my code:
<form action="work.php" method="post">
<table>
<tr>
<td>Email:</td>
<td><input type="text" name="Email" tabindex="1" />
</td>
</tr>
<tr>
<td>Messgae:</td>
<td><textarea name="Message"
rows = "7"
cols = "35"
tabindex = "2" /></textarea>
</td>
</tr>
<tr>
<Td>Time</td>
<td>
<select name="hour" tabindex="3">
<option value="1">1AM</option>
<option value="2">2AM</option>
<option value="3">3AM</option>
<option value="4">4AM</option>
<option value="5">5AM</option>
<option value="6">6AM</option>
<option value="7">7AM</option>
<option value="8">8AM</option>
<option value="9">9AM</option>
<option value="10">10AM</option>
<option value="11">11AM</option>
<option value="12">12PM</option>
<option value="13">1PM</option>
<option value="14">2PM</option>
<option value="15">3PM</option>
<option value="16">4PM</option>
<option value="17">5PM</option>
<option value="18">6PM</option>
<option value="19">7PM</option>
<option value="20">8PM</option>
<option value="21">9PM</option>
<option value="22">10PM</option>
<option value="23">11PM</option>
<option value="24">12AM</option>
</select><br>
<input type="submit" name="formSubmit" value="Submit" >
</form>
And then here is work.php
<?php
$time = $_POST['hour'];
$email1 = $_POST['Email'];
$message1 = $_POST['Message'];
mysql_connect ('localhost', 'myuser', 'mypassword') or die ('Error: ' .mysql_error());
mysql_select_db ("mydatabase");
$query="INSERT INTO Reminder (Email, Message, Time)
VALUES
('$email1','$message1','$time')";
mysql_query($query) or die ('Error submitting');
echo "You Chose: " .$time ;
?>
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.
}
}