Insert 2 Different Values From Drop Down Menu

I am trying to add the category (reception room) into a column called category but also add reception-room into a column called linkcategory.

I am struggling to add ‘reception room’ into both category and linkcategory column.

I also dont know where to add the stringreplace once I am entering reception room into both columns.

Does anyone have any suggestions please?

if(isset($_POST['form_id'])){
    $category = mysql_real_escape_string(trim($_POST['category']));
    $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, category, firstname, surname, email, website, company, building, streetname, state, postcode, country, aboutcompany) VALUES ('".$category."', '".$linkcategory."', '".$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.";
        }
    }
}


Divide and conquer - is it a PHP problem or an SQL problem?


// the string you are assembling - stick it into a variable
$sql = "INSERT INTO organiserdbase (category, category, etc);

// a line of debug - which you comment out or remove b4 going live
echo $sql;

// then carry on as normal
$query = mysql_query($sql);

If its a PHP problem you should see it in the output of $sql.

If its an sql problem, copy that string you echoed out and paste it directly into your database and read any error message.

Also, does this table have an auto-increment field? Are there other fields you do not mention which require a default value?

Make sure error reporting is turned ON, and also read up on mysql_error.

Its the PHP script. I cant enter “reception room” into category but I dont know how to simultaneously add “reception-room” into linkcategory.

I have tried a few methods but Im probably not even close lol

No, it’s your SQL.

You cant insert 2 things into the same field. (you’ve got 2 ‘category’ field callers.)


        $query = mysql_query("INSERT INTO organiserdbase ([COLOR="#FF0000"]category, category[/COLOR], firstname, surname, email, website, company, building, streetname, state, postcode, country, aboutcompany) VALUES ('".$category."', '".$linkcategory."', '".$firstname."', '".$surname."', '".$email."', '".$website."', '".$company."', '".$building."', '".$streetname."', '".$state."', '".$postcode."', '".$country."', '".$aboutcompany."')");

If you want the value of $category in both the ‘category’ and ‘linkcategory’ fields, your query should look like: (changes hilighted blue)

        $query = mysql_query("INSERT INTO organiserdbase (category, [COLOR="#0000FF"]linkcategory[/COLOR], firstname, surname, email, website, company, building, streetname, state, postcode, country, aboutcompany) VALUES ('".$category."', '".[COLOR="#0000FF"]$category[/COLOR]."', '".$firstname."', '".$surname."', '".$email."', '".$website."', '".$company."', '".$building."', '".$streetname."', '".$state."', '".$postcode."', '".$country."', '".$aboutcompany."')");

Thanks, Category is the field I am trying to add into both. (then I will add the hyphen) Is there a way to add a drop down value twice?

I’m confused.

Think of your database table like… an egg carton.

From what you’re telling me…
You’re trying to add a row to the egg carton.
You’re then trying to do this by putting two eggs in the same slot (the category field).

This doesnt work (unless you’ve invented some astoundingly square eggs). So perhaps you need to explain your end goal a bit better? Are you trying to insert -2- entries?

If your trying to add multiple categories to some object, than what you can do is create a link table that holds the id of the object and category (create a new table for category, with a unique id), then you can just manage the table with joins, if that’s what your after…

Hi,

What Im trying to do is have “Reception Room” in a drop down menu.

“Reception Room” enters into “Category”
“Reception-Room” enters into “Link Category”

If I can do this the rest of my site should be very simple to work on.