I have a form that works to either submit data to a MySQL database and then echo an appropriate response to the user OR a version that sends the data to someone who will respond to their inquiry. What I want is:
[ol][li]User fills in form[/li]
[li]User sees response on same web page that echoes firts and last name[/li]
[li]Form contents sent via email to a particular email address[/li]
[li]Form is submitted to MySQL database[/li][/ol]
Yahoo is the host, so using their email form submission, it will send and redirect them to another page that I may specify. If it is not specified, the page automatically redirects to show what the user submitted, which I do not want.
The MySQL version works and echoes the name, but then that would require constant monitoring of the DB, which is not going to happen.
Here is the code…
[php]
<?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO contact (firstname, lastname, emailAddress, phoneNumber, stAddress, aptNumber, city, fiftystates, zipCode, `time`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['firstname'], "text"), GetSQLValueString($_POST['lastname'], "text"), GetSQLValueString($_POST['emailAddress'], "text"), GetSQLValueString($_POST['phoneNumber'], "text"), GetSQLValueString($_POST['stAddress'], "text"), GetSQLValueString($_POST['aptNumber'], "text"), GetSQLValueString($_POST['city'], "text"), GetSQLValueString($_POST['fiftyStates'], "text"), GetSQLValueString($_POST['zipCode'], "text"), GetSQLValueString($_POST['time'], "text")); mysql_select_db($database_**************, $****************); $Result1 = mysql_query($insertSQL, $**********) or die(mysql_error()); } ?>[/php]
[code]<form method=“POST” id=“form1” name=“form1” action="<?php echo $editFormAction; ?>“post”>
First Name* | (Please, let me know who I am contacting) |
Last Name | |
Email Address* | A value is required.Invalid format. |
Phone Number* | Example: (000) 000-0000 |
Street Address | |
Suite | Apt | Unit | |
City | |
State | Select a State Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware Florida Georgia Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachusetts Michigan Minnesota Mississippi Missouri Montana Nebraska Nevada New Hampshire New Jersey New Mexico New York North Carolina North Dakota Ohio Oklahoma Oregon Pennsylvania Rhode Island South Carolina South Dakota Tennessee Texas Utah Vermont Virginia Washington West Virginia Wisconsin Wyoming |
Zip Code* | Invalid format. |
When is the best time to reach you? | |