I have fitted this code back into my existing code so that the whole form works. However when I submit an input it creates 2 lines.
1 line has just “Event Manager” and “event-manager” in.
The other line has only “Event Manager” and all the other inputs which I am also collecting. Do you know who how I can arrange all code that it creates just one line which features “Event Manager” and “event-manager” and all the other information I am collecting.
if(isset($_POST['form_id'])){
$_POST['category'] = trim($_POST['category']);
if(empty($_POST['category'])) {
$error = "Please select a category.";
}
if(!isset($error)) {
$category = mysql_real_escape_string($_POST['category']);
$linkcategory = str_replace(' ', '-',strtolower($_POST['category']));
$linkcategory = mysql_real_escape_string($linkcategory);
$sql = "
INSERT INTO
organiserdbase
SET
category = '".$category."',
linkcategory = '".$linkcategory."'";
$result = mysql_query($sql) or die("An error occurred ".mysql_error());
if($result)
{
echo "success";
}
}
$firstname = mysql_real_escape_string(trim($_POST['firstname']));
$surname = mysql_real_escape_string(trim($_POST['surname']));
$email = mysql_real_escape_string(trim($_POST['email']));
$website = mysql_real_escape_string(trim($_POST['website']));
$company = mysql_real_escape_string(trim($_POST['company']));
$building = mysql_real_escape_string(trim($_POST['building']));
$streetname = mysql_real_escape_string(trim($_POST['streetname']));
$state = mysql_real_escape_string(trim($_POST['state']));
$postcode = mysql_real_escape_string(trim($_POST['postcode']));
$country = mysql_real_escape_string(trim($_POST['country']));
$aboutcompany = mysql_real_escape_string(trim($_POST['aboutcompany']));
$error = false;
if(!isset($category) || empty($category)) {
$error = "Please select a category.";
}
if(!isset($firstname) || empty($firstname)) {
$error = "Please enter a First Name.";
}
if(!isset($surname) || empty($surname)) {
$error = "Please enter a Surname.";
}
if(!isset($email) || empty($email)) {
$error = "Please enter an email.";
}
if(!isset($website) || empty($website)) {
$error = "Please enter a Website Domain.";
}
if(!isset($company) || empty($company)) {
$error = "Please enter a Company Name.";
}
if(!isset($building) || empty($building)) {
$error = "Please enter a Building Name or Number.";
}
if(!isset($streetname) || empty($streetname)) {
$error = "Please enter a Street Name.";
}
if(!isset($state) || empty($state)) {
$error = "Please enter a State.";
}
if(!isset($postcode) || empty($postcode)) {
$error = "Please enter a Zip Code/Post Code.";
}
if(!isset($country) || empty($country)) {
$error = "Please select your country.";
}
if(!isset($aboutcompany) || empty($aboutcompany)) {
$error = "Please enter details about your company.";
}
if(!$error) {
$query = mysql_query("INSERT INTO organiserdbase (category,firstname, surname, email, website, company, building, streetname, state, postcode, country, aboutcompany) VALUES ('".$category."', '".$firstname."', '".$surname."', '".$email."', '".$website."', '".$company."', '".$building."', '".$streetname."', '".$state."', '".$postcode."', '".$country."', '".$aboutcompany."')");
if($query) {
} else {
$error = "There was a problem with the submission. Please try again.";
}
}
}
?>
The code wasn’t entering either the category or linkcategory so I had a play about with it.
The code now doesn’t enter the linkcategory and it will enter information whilst some boxes are blank but will raise the error messages.
So if someone does not enter an email address it will raise the error message “Please enter an email.” but it will submit a line to the DV with the email box empty.
Any thoughts on how to fix these two?
<?php
function mysql_real_escape_array($t)
{
return array_map("mysql_real_escape_string",$t);
}
function trim_array($ar)
{
return array_map("trim",$ar);
}
if(isset($_POST['form_id']))
{
$_POST = mysql_real_escape_array($_POST);
$_POST = trim_array($_POST);
$error = "";
if(!isset($_POST['category']) || empty($_POST['category'])) {
$error = "Please select a category.";
}
if(!isset($_POST['firstname']) || empty($_POST['firstname'])) {
$error.= " Please enter a First Name.";
}
if(!isset($_POST['surname']) || empty($_POST['surname'])) {
$error.= " Please enter a Surname.";
}
if(!isset($_POST['email']) || empty($_POST['email'])) {
$error.= " Please enter an email.";
}
if(!isset($_POST['website']) || empty($_POST['website'])) {
$error.= " Please enter a Website Domain.";
}
if(!isset($_POST['company']) || empty($_POST['company'])) {
$error.= " Please enter a Company Name.";
}
if(!isset($_POST['building']) || empty($_POST['building'])) {
$error.= " Please enter a Building Name or Number.";
}
if(!isset($_POST['streetname']) || empty($_POST['streetname'])) {
$error.= " Please enter a Street Name.";
}
if(!isset($_POST['state']) || empty($_POST['state'])) {
$error.= " Please enter a State.";
}
if(!isset($_POST['postcode']) || empty($_POST['postcode'])) {
$error.= " Please enter a Zip Code/Post Code.";
}
if(!isset($_POST['country']) || empty($_POST['country'])) {
$error.= " Please select your country.";
}
if(!isset($_POST['aboutcompany']) || empty($_POST['aboutcompany'])) {
$error.= " Please enter details about your company.";
}
if($error != "")
{
$sql = "
INSERT INTO
organiserdbase
SET
category = '".$_POST['category']."',
linkcategory = '".str_replace(' ', '-',strtolower($_POST['linkcategory']))."',
firstname = '".$_POST['firstname']."',
surname = '".$_POST['surname']."',
email = '".$_POST['email']."',
website = '".$_POST['website']."',
company = '".$_POST['company']."',
building = '".$_POST['building']."',
streetname = '".$_POST['streetname']."',
state = '".$_POST['state']."',
postcode = '".$_POST['postcode']."',
country = '".$_POST['country']."',
aboutcompany = '".$_POST['aboutcompany']."'";
$result = mysql_query($sql) or die("An error occurred ".mysql_error());
if($result)
{
echo "success";
}
}
else
{
echo "You have the following errors: ".$error;
}
}
?>