Форма PHP не отправляется в базу данных MYSQL

В настоящее время я пытаюсь получить форму для отправки данных, которые люди заполняют в базу данных MYSQL. Форма функционировала правильно, прежде чем я добавил этот код, она выводит информацию на мою электронную почту.

Вот файл connection.php:

<?php

function Connect()
{
$dbhost = "localhost:8889";
$dbuser = "******";
$dbpass = "******";
$dbname = "sfus18_speakers";

$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error);

return $conn;
}

?>

и вот полный код speaker.php:

    <?phpif(isset($_POST['email'])) {// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "xxx";

$email_subject = "yyy";
function died($error) {

// your error code can go here

echo "We are very sorry, but there were error(s) found with the form you submitted. ";

echo "These errors appear below.<br /><br />";

echo $error."<br /><br />";

echo "Please go back and fix these errors.<br /><br />";

die();

}// validation expected data exists

if(!isset($_POST['fName']) ||

!isset($_POST['lName']) ||

!isset($_POST['email']) ||

!isset($_POST['cell']) ||

!isset($_POST['company']) ||

!isset($_POST['title']) ||

!isset($_POST['address']) ||

!isset($_POST['address2']) ||

!isset($_POST['city']) ||

!isset($_POST['state']) ||

!isset($_POST['zip']) ||

!isset($_POST['shirt']) ||!isset($_POST['bio']) ||

!isset($_POST['preTitle']) ||

!isset($_POST['subTitle']) ||

!isset($_POST['format']) ||

!isset($_POST['abstract']) ||

!isset($_POST['audience']) ||

!isset($_POST['additional']))

{

died('We are sorry, but there appears to be a problem with the form you submitted.');

}$fName = $conn->mysqli_real_escape_string ($_POST['fName']); // required

$lName = $conn->mysqli_real_escape_string ($_POST['lName']); // required

$email = $conn->mysqli_real_escape_string ($_POST['email']); // required

$cell = $conn->mysqli_real_escape_string ($_POST['cell']); // required

$company = $conn->mysqli_real_escape_string ($_POST['company']); // required

$title = $conn->mysqli_real_escape_string ($_POST['title']); // required

$address = $conn->mysqli_real_escape_string ($_POST['address']); // required

$address2 = $conn->mysqli_real_escape_string ($_POST['address2']); // not required

$city = $conn->mysqli_real_escape_string ($_POST['city']); // required

$state = $conn->mysqli_real_escape_string ($_POST['state']); // required

$zip = $conn->mysqli_real_escape_string ($_POST['zip']); // required

$shirt = $conn->mysqli_real_escape_string ($_POST['shirt']); // required$bio = $conn->mysqli_real_escape_string ($_POST['bio']); // required

$preTitle = $conn->mysqli_real_escape_string ($_POST['preTitle']); // required

$subTitle = $conn->mysqli_real_escape_string ($_POST['subTitle']); // not required

$format = $conn->mysqli_real_escape_string ($_POST['format']); // required

$abstract = $conn->mysqli_real_escape_string ($_POST['abstract']); // required

$audience = $conn->mysqli_real_escape_string ($_POST['audience']); // required

$additional = $conn->mysqli_real_escape_string ($_POST['additional']); // not required$error_message = "";

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

if(!preg_match($email_exp,$email)) {

$error_message .= 'The Email Address you entered does not appear to be valid.<br />';

}

$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($string_exp,$fName)) {

$error_message .= 'The First Name you entered does not appear to be valid.<br />';

}

if(!preg_match($string_exp,$lName)) {

$error_message .= 'The Last Name you entered does not appear to be valid.<br />';

}

$string_exp = "/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/";

if(preg_match($string_exp,$cell)) {

$error_message .= 'The cell phone number you entered does not appear to be valid.<br />';

}

if(preg_match($string_exp,$company)) {

$error_message .= 'The company you entered does not appear to be valid.<br />';

}

if(preg_match($string_exp,$title)) {

$error_message .= 'The job title you entered does not appear to be valid.<br />';

}

if(preg_match($string_exp,$address)) {

$error_message .= 'The address you entered does not appear to be valid.<br />';

}

if(preg_match($string_exp,$city)) {

$error_message .= 'The city you entered does not appear to be valid.<br />';

}

if(preg_match($string_exp,$state)) {

$error_message .= 'The state/province you entered does not appear to be valid.<br />';

}

if(preg_match($string_exp,$zip)) {

$error_message .= 'The postal code you entered does not appear to be valid.<br />';

}

if(preg_match($string_exp,$shirt)) {

$error_message .= 'The shirt size you entered does not appear to be valid.<br />';

}

if(preg_match($string_exp,$bio)) {

$error_message .= 'Please enter your biography.<br />';

}

if(preg_match($string_exp,$preTitle)) {

$error_message .= 'Please enter the title of your presentation.<br />';

}

if(preg_match($string_exp,$format)) {

$error_message .= 'Please enter the format of your presentation.<br />';

}

if(preg_match($string_exp,$abstract)) {

$error_message .= 'Please enter the abstract.<br />';

}

if(preg_match($string_exp,$audience)) {

$error_message .= 'Please enter the audience level of your presentation.<br />';

}

if(strlen($error_message) > 0) {

died($error_message);

}

$email_message = "";function clean_string($string) {

$bad = array("content-type","bcc:","to:","cc:","href");

return str_replace($bad,"",$string);

}$email_message .= "First Name: ".clean_string($fName)."\n";

$email_message .= "Last Name: ".clean_string($lName)."\n";

$email_message .= "Email: ".clean_string($email)."\n";

$email_message .= "Cell Phone: ".clean_string($cell)."\n";

$email_message .= "Company: ".clean_string($company)."\n";

$email_message .= "Title: ".clean_string($title)."\n";

$email_message .= "Address: ".clean_string($address)."\n";

$email_message .= "Address2: ".clean_string($address2)."\n";

$email_message .= "City: ".clean_string($city)."\n";

$email_message .= "State: ".clean_string($state)."\n";

$email_message .= "Zip: ".clean_string($zip)."\n";

$email_message .= "Shirt Size: ".clean_string($shirt)."\n";

$email_message .= "Bio: ".clean_string($bio)."\n";

$email_message .= "Presentation Title: ".clean_string($preTitle)."\n";

$email_message .= "Subtitle: ".clean_string($subTitle)."\n";

$email_message .= "Format: ".clean_string($format)."\n";

$email_message .= "Abstract: ".clean_string($abstract)."\n";

$email_message .= "Audience Level: ".clean_string($audience)."\n";

$email_message .= "Additional Information: ".clean_string($additional)."\n";

// create email headers

$headers = 'From: xxx'.$email_from."\r\n".

'Reply-To: '.$email_from."\r\n" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);?>

<?php
}
extract($_POST);

echo "<pre>";

print_r($_POST);

$query = "INSERT into tb_cform (fName, lName, email, cell, company, title, address, address2, city, state, zip, shirt, bio, preTitle, subTitle, format, abstract, audience, additional) VALUES ('" . $fName . "', '" . $lName . "', '" . $email . "', '" . $cell . "', '" . $company . "', '" . $title . "', '" . $address . "', '" . $address2 . "', '" . $city . "', '" . $state . "', '" . $zip . "', '" . $shirt . "', '" . $bio . "', '" . $preTitle . "', '" . $subTitle . "', '" . $format . "', '" . $abstract . "', '" . $audience . "', '" . $additional . "',)";

print_r($query);

?>

Есть идеи, что я делаю не так?

РЕДАКТИРОВАТЬ 1: Вот форма (speakerapp.php), это довольно долго. Форма работала правильно, прежде чем я попытался отправить данные в MySQL.

<form id="form_923064" class="appnitro"  method="post" action="speaker.php">
<ul>
<li id="speakerLi">
<label class="fName" for="fName">First Name<span>*</span> </label>

<input id="fName" required name="fName" data-toggle="tooltip" class="speakerForm" type="text" title="First Name is Required" maxlength="55" value=""/>
</li>
<li id="speakerLi">
<label class="lName" for="lName">Last Name<span>*</span> </label>

<input id="lName" required name="lName" data-toggle="tooltip" class="speakerForm" type="text" title="Last Name is Required" maxlength="55" value=""/>
</li>
<li id="speakerLi">
<label class="email" for="email">Email Address<span>*</span> </label>

<input id="email" required name="email" data-toggle="tooltip" class="speakerForm" type="text" title="Email is Required" maxlength="55" value=""/>
</li>
<li id="speakerLi">
<label class="cell" for="cell">Cell Phone<span>*</span> (Include Country Code if Outside the U.S.) </label>

<input id="cell" required name="cell" class="speakerForm" type="text" maxlength="15" value=""/>

</li>       <li id="speakerLi">
<label class="description" for="company">Company/Organization Name<span>*</span> </label>

<input id="company" required name="company" class="speakerForm" type="text" maxlength="30" value=""/>

</li>       <li id="speakerLi">
<label class="title" for="title">Title/Job Role<span>*</span> </label>

<input id="title" required name="title" class="speakerForm" type="text" maxlength="30" value=""/>

</li>       <li id="speakerLi">
<label class="description" for="address">Street Address<span>*</span> </label>

<input id="address" required name="address" class="speakerForm" type="text" maxlength="50" value=""/>

</li>       <li id="speakerLi">
<label class="description" for="address2">Street Address 2</label>

<input id="address2"  name="address2" class="speakerForm" type="text" maxlength="50" value=""/>

</li>       <li  id="speakerLi" >
<label class="description" for="city">City<span>*</span> </label>

<input id="city" required name="city" class="speakerForm" type="text" maxlength="30" value=""/>

</li>       <li  id="speakerLi">
<label class="description" for="state">State/Province<span>*</span> </label>

<input id="state" required name="state" class="speakerForm" type="text" maxlength="20" value=""/>

</li>       <li id="speakerLi">
<label class="description" for="zip">Postal Code<span>*</span> </label>

<input id="zip" required name="zip" class="speakerForm" type="text" maxlength="10" value=""/>

</li>       <li id="speakerLi">
<label class="shirtSize" for="shirt">Shirt Size<span>*</span> </label>
<br>
<select class="element select medium" id="shirt" required name="shirt">
<option value="" selected="selected"></option>
<option value="small" >Small</option>
<option value="medium" >Medium</option>
<option value="large" >Large</option>
<option value="xl" >XL</option>
<option value="xxl" >XXL</option>

</select>

</li></ul><h2 class="post-title2"><strong>Biography</strong></h2>

<p>Please include a short description of yourself, your work history, your interests.</p>

<li id="speakerLi">
<label class="description" for="bio">Short Biography (1,000 Characters Maximum)<span>*</span> </label> <br>

<textarea id="bio" required name="bio" class="speakerForm" type="text" maxlength="1000" value=""></textarea>

</li>
<h2 class="post-title2"><strong>Presentation Information</strong></h2>
<ul>
<li id="speakerLi">
<label class="description" for="preTitle">Title<span>*</span> </label>
<input id="preTitle" required name="preTitle" class="speakerForm" type="text" maxlength="100" value=""/>
</li>
<li id="speakerLi">
<label class="description" for="subTitle">Subtitle </label>
<input id="subTitle" name="subTitle" class="speakerForm" type="text" maxlength="100" value=""/>
</li>
<li id="speakerLi">
<label class="shirtSize" required for="format">Presentation Format<span>*</span> </label>
<br>
<select class="element select medium" id="format" name="format">
<option value="" selected="selected"></option>
<option value="presentation">Presentation</option>
<option value="hands-on">Hands-On Lab</option>
<option value="panel">Panel</option>
<option value="interactive">Audience-Interactive Session</option>
</select>
</li>
</ul>
<li id="speakerLi">
<label class="description" for="abstract">Presentation Abstract (1,000 Characters Maximum)<span>*</span> </label>
<br>
<textarea id="abstract" required name="abstract" class="speakerForm" type="text" maxlength="1000" value=""></textarea>
</li>
<ul>
<li id="speakerLi">
<label class="shirtSize" for="audience">Audience Expertise Level<span>*</span> </label>
<br>
<select required class="element select medium" id="audience" name="audience">
<option value="" selected="selected"></option>
<option value="Beginner">Beginner</option>
<option value="Intermediate">Intermediate</option>
<option value="Advanced">Advanced</option>
<option value="Developer">Developer</option>
</select>
</li>
</ul>
<h2 class="post-title2"><strong>Additional Questions/Requests</strong></h2>
<li id="speakerLi">
<textarea id="additional" name="additional" class="speakerForm" type="text" maxlength="1000" value=""></textarea>
</li><li class="buttons">
<input type="hidden" name="form_id" value="923064" />

<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</form>

0

Решение

удалить последний «,» в запросе

<?php
$query   = "INSERT into tb_cform (fName, lName, email, cell, company, title, address, address2, city, state, zip, shirt, bio, preTitle, subTitle, format, abstract, audience, additional) VALUES ('".$fName."', '".$lName."', '".$email."', '".$cell."', '".$company."', '".$title."', '".$address."', '".$address2."', '".$city."', '".$state."', '".$zip."', '".$shirt."', '".$bio."', '".$preTitle."', '".$subTitle."', '".$format."', '".$abstract."', '".$audience."', '".$additional."')";
?>
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector