Codice PHP:
Salve a tutti sto cercando di recuperare dei dati spediti via mail per poi inserli nella tabella di un database, ho creato la query ma il nulla i dati non vengono salvati qualcuno può aiutarmi, non sò dove sia l'errore...
<?php
// User settings
$to = "davidgrace@romafitnesscenter.com";
$subject = "Richiesta prova gratuita ";
// Include extra form fields and/or submitter data?
// false = do not include
$extra = array(
"form_subject" => true,
"form_cc" => true,
"ip" => true,
"user_agent" => true
);
// Process
$action = isset($_POST["action"]) ? $_POST["action"] : "";
if (empty($action)) {
// Send back the contact form HTML
$output = "<div style='display:none'>
<div class='contact-top'></div>
<div class='contact-content'>
<h1 class='contact-title'>Richiedi la tua prova:</h1>
<div class='contact-loading' style='display:none'></div>
<div class='contact-message' style='display:none'></div>
<form action='#' style='display:none'>
<label for='contact-name'>*Nome:</label>
<input type='text' id='contact-name' class='contact-input' name='name' tabindex='1006' />
<label for='contact-cognome'>*Cognome:</label>
<input type='text' id='contact-cognome' class='contact-input' name='cognome' tabindex='1005' />
<label for='contact-telefono'>*Telefono:</label>
<input type='text' id='contact-telefono' class='contact-input' name='telefono' tabindex='1001' />
<label for='contact-email'>*Email:</label>
<input type='text' id='contact-email' class='contact-input' name='email' tabindex='1002' />
<label for='contact-sede'>*Sede:</label>
<select id='contact-sede' class='contact-input' name='sede' cols='40' rows='4' tabindex='1008'>
<option value='' selected='selected'>Scegli.......</option>
<option value='Garbatella'>Garbatella </option>
<option value='Portuense'>Portuense </option>
</select>";
if ($extra["form_subject"]) {
$output .= "
<label for='contact-subject'>Subject:</label>
<input type='text' id='contact-subject' class='contact-input' name='subject' value='Richiesta di una prova gratutita' tabindex='1003' />";
}
$output .= "
<label for='contact-message'>*Attività:</label>
<select id='contact-message' class='contact-input' name='message' cols='40' rows='4' tabindex='1004'>
<option value='' selected='selected'>Scegli.......</option>
<option value='Body_Ballance'>Body Ballance </option>
<option value='Body_Sculpt'>Body Sculpt </option>
<option value='Hatha_yoga '>Hatha yoga </option>
<option value='Stretching'>Stretching</option>
<option value='Total Body'>Total Body</option>
<option value='Balli_di_gruppo'>Balli di Gruppo</option>
<option value='Salsa_Cubana'>Salsa Cubana</option>
<option value='Afro'>Afro</option>
<option value='Soft Pilates'>Soft Pilates</option>
<option value='Tone Pilates'>Tone Pilates</option>
<option value='Pilates'>Pilates</option>
<option value='Pump'>Pump</option>
<option value='Gym Soft'>Gym Soft</option>
<option value='Yoga De Rose'>Yoga - (De Rose)</option>
<option value='Ginnastica Posturale'>Ginnastica Posturale</option>
<option value='Spinning'>Spinning</option>
<option value='Tonificazione'>Tonificazione</option>
<option value='Tone_Up'>Tone Up</option>
<option value='Interval Training'>Interval Training</option>
<option value='Total Work Out'>Total Work Out</option>
<option value='Total Body'>Total Body</option>
<option value='Step Coreografico'>Step Coreografico</option>
<option value='Corpo Libero'>Corpo Libero</option>
<option value='K B E'>K.B.E</option>
<option value='Karate'>Karate</option>
<option value='Difesa_Personale'>Difesa Personale</option>
<option value='G a g'>G.a.g.</option>
</select>
"
;
if ($extra["form_cc"]) {
$output .= "
<label></label>
<input type='checkbox' id='contact-cc' checked='checked' name='cc' value='1' tabindex='1005' /> <span class='contact-cc'> Non togliere il flag per ricevere l' E-Mail di conferma</span>
";
}
$output .= "
<label></label>
<button type='submit' class='contact-send contact-button' tabindex='1006'>Send</button>
<button type='submit' class='contact-cancel contact-button simplemodal-close' tabindex='1007'>Cancel</button>
<input type='hidden' name='token' value='" . smcf_token($to) . "'/>
</form>
</div>
<div class='contact-bottom'></div>
</div>";
echo $output;
}
else if ($action == "send") {
// Send the email
$name = isset($_POST["name"]) ? $_POST["name"] : "";
$cognome = isset($_POST["cognome"]) ? $_POST["cognome"] : "";
$telefono = isset($_POST["telefono"]) ? $_POST["telefono"] : "";
$email = isset($_POST["email"]) ? $_POST["email"] : "";
$subject = isset($_POST["subject"]) ? $_POST["subject"] : $subject;
$message = isset($_POST["message"]) ? $_POST["message"] : "";
$sede = isset($_POST["sede"]) ? $_POST["sede"] : "";
$cc = isset($_POST["cc"]) ? $_POST["cc"] : "";
$token = isset($_POST["token"]) ? $_POST["token"] : "";
// make sure the token matches
if ($token === smcf_token($to)) {
smcf_send($name, $cognome, $telefono, $email, $subject, $message, $sede, $cc);
echo "Il tuo messaggio è stato inviato con successo.";
}
else {
echo "Non è stato possibile verificare il messaggio.";
}
}
function smcf_token($s) {
return md5("smcf-" . $s . date("WY"));
}
// Validate and send email
function smcf_send($name, $cognome, $telefono, $email, $subject, $message, $sede, $cc) {
global $to, $extra;
// Filter and validate fields
$name = smcf_filter($name);
$subject = smcf_filter($subject);
$email = smcf_filter($email);
if (!smcf_validate_email($email)) {
$subject .= " - invalid email";
$message .= "\n\nBad email: $email";
$email = $to;
$cc = 0; // do not CC "sender"
}
// Add additional info to the message
if ($extra["ip"]) {
$message .= "\n\nIP: " . $_SERVER["REMOTE_ADDR"];
}
if ($extra["user_agent"]) {
$message .= "\n\nUSER AGENT: " . $_SERVER["HTTP_USER_AGENT"];
}
// Set and wordwrap attivita body
$body = "
Gentile $name $cognome.
Grazie per aver scelto Roma Fitness Center, al più presto sarai ricontattato dal nostro staff.\n
Cordiali saluti\n
David Grace\n
Nuova richiesta di una prova gratuita da parte del Sig.\n
Nome: $name\n
Cognome: $cognome\n
E-Mail: $email\n
Telefono: $telefono\n
Sede scelta: $sede\n
Attività scelta: $message ";
$body .= "";
$body = wordwrap($body, 70);
// Build header
$headers = "From: $email\n";
if ($cc == 1) {
$headers .= "Cc: $email\n";
}
$headers .= "X-Mailer: PHP/SimpleModalContactForm";
// UTF-8
if (function_exists('mb_encode_mimeheader')) {
$subject = mb_encode_mimeheader($subject, "UTF-8", "B", "\n");
}
else {
// you need to enable mb_encode_mimeheader or risk
// getting emails that are not UTF-8 encoded
}
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=utf-8\n";
$headers .= "Content-Transfer-Encoding: quoted-printable\n";
// Send email
@mail($to, $subject, $body, $headers) or
die("Pultroppo, un problema al server ha impedito la consegna del messaggio.");
}
require_once('../Connections/fitnesscenter.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;
}
}
$action = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$action .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "")) {
$insertSQL = sprintf("INSERT INTO richieste_prova (name, cognome, email, telefono, message) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['cognome'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['telefono'], "text"),
GetSQLValueString($_POST['message'], "text"));
mysql_select_db($database_fitnesscenter, $fitnesscenter);
$Result1 = mysql_query($insertSQL, $fitnesscenter) or die(mysql_error());
}
// Remove any un-safe values to prevent email injection
function smcf_filter($value) {
$pattern = array("/\n/","/\r/","/content-type:/i","/to:/i", "/from:/i", "/cc:/i");
$value = preg_replace($pattern, "", $value);
return $value;
}
// Validate email address format in case client-side validation "fails"
function smcf_validate_email($email) {
$at = strrpos($email, "@");
// Make sure the at (@) sybmol exists and
// it is not the first or last character
if ($at && ($at < 1 || ($at + 1) == strlen($email)))
return false;
// Make sure there aren't multiple periods together
if (preg_match("/(\.{2,})/", $email))
return false;
// Break up the local and domain portions
$local = substr($email, 0, $at);
$domain = substr($email, $at + 1);
// Check lengths
$locLen = strlen($local);
$domLen = strlen($domain);
if ($locLen < 1 || $locLen > 64 || $domLen < 4 || $domLen > 255)
return false;
// Make sure local and domain don't start with or end with a period
if (preg_match("/(^\.|\.$)/", $local) || preg_match("/(^\.|\.$)/", $domain))
return false;
// Check for quoted-string addresses
// Since almost anything is allowed in a quoted-string address,
// we're just going to let them go through
if (!preg_match('/^"(.+)"$/', $local)) {
// It's a dot-string address...check for valid characters
if (!preg_match('/^[-a-zA-Z0-9!#$%*\/?|^{}`~&\'+=_\.]*$/', $local))
return false;
}
// Make sure domain contains only valid characters and at least one period
if (!preg_match("/^[-a-zA-Z0-9\.]*$/", $domain) || !strpos($domain, "."))
return false;
return true;
}
exit;
?>