SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    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?


    Code:
    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.";
            }
        }
    }

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Divide and conquer - is it a PHP problem or an SQL problem?

    PHP Code:
    // 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.

  3. #3
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    No, it's your SQL.

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

    Code:
            $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 you want the value of $category in both the 'category' and 'linkcategory' fields, your query should look like: (changes hilighted blue)
    Code:
            $query = mysql_query("INSERT INTO organiserdbase (category, linkcategory, firstname, surname, email, website, company, building, streetname, state, postcode, country, aboutcompany) VALUES ('".$category."', '".$category."', '".$firstname."', '".$surname."', '".$email."', '".$website."', '".$company."', '".$building."', '".$streetname."', '".$state."', '".$postcode."', '".$country."', '".$aboutcompany."')");
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    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?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Zealot maxdream01's Avatar
    Join Date
    Feb 2011
    Location
    USA
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    Thanks, Category is the field I am trying to add into both.
    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...
    PHP is FUN

  8. #8
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •