justlukeyou Posted July 3, 2012 Share Posted July 3, 2012 Hi, Does anyone know if it is possible to submit 2 values to a database from a drop down menu? I have "Reception Room" being submitted to 'category' but is it possible to submit "Reception-Room" to a column called 'linkcategory'. Or when Reception Room is submitted can I use some form of code to add 'Reception-Room' to another code? <option value="Reception Room" >Reception Room</option> <option value="Hotel" >Hotel</option> <option value="Night Club" >Night Club</option> Quote Link to comment Share on other sites More sharing options...
xyph Posted July 3, 2012 Share Posted July 3, 2012 Yes, it's possible. You need to work on your terminology though... it's all over the place. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 4, 2012 Author Share Posted July 4, 2012 Not sure what you mean. Quote Link to comment Share on other sites More sharing options...
Bradley99 Posted July 4, 2012 Share Posted July 4, 2012 With your IF Post submit code, I presume you'll have an INSERT INTO category. . . Just add another INSERT INTO underneath that to enter it into the other column. Quote Link to comment Share on other sites More sharing options...
Bradley99 Posted July 4, 2012 Share Posted July 4, 2012 So. . if ($_POST['Submit']){ $category = $_POST['selectname']; { mysql_query("INSERT INTO category (`category`) VALUES ("'$category'')") or die (mysql_error()); mysql_query("INSERT INTO linkcategory (`category`) VALUES ("'$category'')") or die (mysql_error()); Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 5, 2012 Author Share Posted July 5, 2012 Hi, Is it possible to add "reception-room" into linkcategory so linkcategory now has a hyphen. Would I add a string replace to linkcategory so it adds a hyphen. However, I am inserting the "reception room" from a drop down so can I have to two values in the drop down. "reception room" and "reception-room". mysql_query("INSERT INTO category (`category`) VALUES ("'$category'')") or die (mysql_error()); mysql_query("INSERT INTO linkcategory (`linkcategory`) VALUES ("'$linkcategory'')") or die (mysql_error()); Quote Link to comment Share on other sites More sharing options...
jcbones Posted July 5, 2012 Share Posted July 5, 2012 2 of the same values in a select list would confuse the user. str_replace would work well here. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 17, 2012 Author Share Posted July 17, 2012 Im having a hell of a time with this. I am trying to add the category (reception room) into a column called category but also add reception-room into a column called linkcategory. Firstly I am struggling to add 'reception room' into both category and linkcategory column. Secondly I 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."; } } } Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 19, 2012 Author Share Posted July 19, 2012 Hi, Does anyone have any suggestions please? Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 19, 2012 Share Posted July 19, 2012 I think you should be storing reception-room and Reception Room in the SAME row in the same table. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 19, 2012 Author Share Posted July 19, 2012 By echoing reception room with a string replace? Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 19, 2012 Share Posted July 19, 2012 How are you populating your original list of values? Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 19, 2012 Author Share Posted July 19, 2012 I have a drop down of around 50 values without the hyphen. If I can enter the value with a hyphen it will save a huge amount of time in building the site. Thats my plan anyway. </div> <div id="forminputright"> <select class="element select medium" id="category" name="category"> </div> <option value="" selected="selected">Your Job Role:</option> <option value="Event Manager" >Event Manager</option> <option value="Event Managent Courses" >Event Managent Courses</option> <option value="Event Management Software" >Event Management Software</option> <option value="Entertainment Staff" >Entertainment Staff</option> Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 19, 2012 Share Posted July 19, 2012 How does that drop down get populated though? You manually wrote each entry? Yes, you could use strtolower and str_replace to convert the name to the link slug. Then make sure they are stored together, in only one place. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 19, 2012 Author Share Posted July 19, 2012 Hi, Yes I manually wrote each entry for the drop down menu. The thing is I would find it much easier for the rest of the site if I can have to columns, one with and one without the hyphen. Once I can enter in both "reception room" and "reception-room" the rest should be quite simple. Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted July 19, 2012 Share Posted July 19, 2012 TRY to use the explode function. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 24, 2012 Author Share Posted July 24, 2012 Hi, Im a bit confused how these are stored in the same place. How does that process work please? Is it not possible at all to enter into two columns, one with a hyphen. The rest should be simple. Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 24, 2012 Share Posted July 24, 2012 Yes it is, you're being quite vague with your question though. Look. INSERT INTO table (link, name) VALUES('reception-room', 'Reception Room'); That will work just fine. Where are you stuck? Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 25, 2012 Author Share Posted July 25, 2012 Brilliant thanks, So do I just need to drop that into the drop menu code and add the insert code mysql_query("INSERT INTO link (`link`) VALUES ("'$link'')") or die (mysql_error()); I shall give it a go. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 26, 2012 Author Share Posted July 26, 2012 Hi, I had a go at this however I am stuck as to how to add two values into the dropdown area. I'm using the fields 'category' and 'linkcategory'. <select class="element select medium" id="category, linkcategory" id="category, linkcategory"> <option value="Reception Room" >Reception Room</option> I have tried a few variations but cant get it to work. Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 26, 2012 Share Posted July 26, 2012 *headdesk* Dude, you've been given several answers, and what you're trying to do is so mind numbingly simple... Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 26, 2012 Author Share Posted July 26, 2012 I'm trying my best to get to work, thats all I can do. This is all my code, Im almost there with it (hopefully) <?php if(isset($_POST['form_id'])){ $category = mysql_real_escape_string(trim($_POST['category'])); $linkcategory = mysql_real_escape_string(trim($_POST['linkcategory'])); $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, linkcategory, 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."; } } } ?> <div id="registerpagecell"> <div id="registerpageheaderorganiser"> Create Your Organiser Profile </div> <div id="registerform"> <form id="form_id" class="appnitro" method="post" action=""> <?php if($error) echo "<span style=\"color:#ff0000;\">".$error."</span><br /><br />"; ?> <ul > <div id="forminputcell"> <li id="li_1" > <div id="forminputleft"> <label class="description" for="element_3">Your Job Role:</label> </div> <div id="forminputright"> <select class="element select medium" id="category, linkcategory" > </div> <option value="" selected="selected">Venue:</option> <option VALUES('Reception Room', 'reception-room') >Reception Room</option> Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 26, 2012 Share Posted July 26, 2012 You can't have more than one value. You can however manipulate the value after it's chosen. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 26, 2012 Author Share Posted July 26, 2012 So should I not be doing this: INSERT INTO table (link, name) VALUES('reception-room', 'Reception Room'); Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 26, 2012 Share Posted July 26, 2012 I give up. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.