hansman Posted July 18, 2008 Share Posted July 18, 2008 Hello, i currently ran into major problems not thiking this scheme out and realized that its not possible, maybe someone could help me I have a table "ad" with fields like, State, County, Name, Username, Passoword, City. i have a drop down menu where a user can select their state, and a list of countys that have been entered for that state is listed. Once they click the county it shows all the names in the county. This works no problem. However, when i insert the "County" with mutiple names such as "county1, county2), i can use the explode() function but i need to insert them into the "County" field and make sure it is not a duplicate. I was thinking i would need to make another table with countys, states and then link it to the table "ad" by "name" any ideas how i can do this? Quote Link to comment Share on other sites More sharing options...
unkwntech Posted July 18, 2008 Share Posted July 18, 2008 Create a new table and give the county name field the unique property, in MySQL. Quote Link to comment Share on other sites More sharing options...
pfkdesign Posted July 18, 2008 Share Posted July 18, 2008 hi use comma-separate-list or checkbox to insert, <? if (isset($insNumRows)) { for ($I=1; $I<=$insNumRows; $I++) { if (isset($_POST["county$I"]) && is_array($_POST["county$I"])) { $_POST["county$I"] = implode(",", $_POST["county$I"]); $HTTP_POST_VARS["county$I"] = $_POST["county$I"]; } } } ?> regards Quote Link to comment Share on other sites More sharing options...
hansman Posted July 18, 2008 Author Share Posted July 18, 2008 with pfkdesin wpuld i still create a new table? Quote Link to comment Share on other sites More sharing options...
pfkdesign Posted July 18, 2008 Share Posted July 18, 2008 no you don't need another database, it will store all in one filed of your table and all of your entry, will separate by "," comma. regards Quote Link to comment Share on other sites More sharing options...
hansman Posted July 18, 2008 Author Share Posted July 18, 2008 so i have the $_POST['county'] comming from the other page, i dont really understand that statments variables, what is the variable going into the dtatabse in the INSERT query Quote Link to comment Share on other sites More sharing options...
pfkdesign Posted July 18, 2008 Share Posted July 18, 2008 "county " specifying the name of the multiple selection element and "," the delimiter to use. <? if (isset($insNumRows)) { for ($I=1; $I<=$insNumRows; $I++) { if (isset($_POST["county$I"]) && is_array($_POST["county$I"])) { ---------------------------^ name of your menu/list---------^ $_POST["county$I"] = implode(",", $_POST["county$I"]); -----------------^ name of your menu/list ------------^ $HTTP_POST_VARS["county$I"] = $_POST["county$I"]; ------------------------------^ name of your menu/list---^ } } } ?> and in your form --> if the name of the filed is "county", you will change it as "county[]" otherwise php will recognize only one selection. Quote Link to comment Share on other sites More sharing options...
hansman Posted July 18, 2008 Author Share Posted July 18, 2008 Does this make sense? The form value is county[] i tired it out and the valuse of county is set to "Array" $state = $_SESSION['state']; $name=$_POST['name']; $email=$_POST['email']; $state=$_POST['state']; $user=$_POST['user']; if (isset($insNumRows)) { for ($I=1; $I<=$insNumRows; $I++) { if (isset($_POST["county$I"]) && is_array($_POST["county$I"])) { $_POST["county$I"] = implode(",", $_POST["county$I"]); $HTTP_POST_VARS["county$I"] = $_POST["county$I"]; } } } $password=$_POST['password']; $sql="INSERT INTO ad (name, email, county, state, user, password)VALUES('$name', '$email', '$county', '$state', '$user', '$password')"; Quote Link to comment Share on other sites More sharing options...
pfkdesign Posted July 18, 2008 Share Posted July 18, 2008 did you change the form value or name of the element=(list/menu or checkbox)? Quote Link to comment Share on other sites More sharing options...
hansman Posted July 18, 2008 Author Share Posted July 18, 2008 well it is a form that i will type in the county manually, and then the page will display what ever counties have been typed in Quote Link to comment Share on other sites More sharing options...
pfkdesign Posted July 18, 2008 Share Posted July 18, 2008 send the code plz (the form) Quote Link to comment Share on other sites More sharing options...
hansman Posted July 18, 2008 Author Share Posted July 18, 2008 <form action="insertadnow.php" method="post"> <p align="center">Company Name:<br /> <input name="name" type="text" /> <br /> <p align="center">State:<br /> <select name="state"> <option>AK</option> <option>AL</option> <option>AR</option> <option>AZ</option> <option>CA</option> <option>CO</option> <option>CT</option> <option>DE</option> <option>FL</option> <option>GA</option> <option>HI</option> <option>IA</option> <option>ID</option> <option>IL</option> <option>IN</option> <option>KS</option> <option>KY</option> <option>LA</option> <option>MA</option> <option>MD</option> <option>ME</option> <option>MI</option> <option>MN</option> <option>MO</option> <option>MS</option> <option>MT</option> <option>NC</option> <option>ND</option> <option>NE</option> <option>NH</option> <option>NJ</option> <option>NM</option> <option>NV</option> <option>NY</option> <option>OH</option> <option>OK</option> <option>OR</option> <option>PA</option> <option>RI</option> <option>SC</option> <option>SD</option> <option>TN</option> <option>TX</option> <option>UT</option> <option>VA</option> <option>WA</option> <option>WI</option> <option>WV</option> <option>WY</option> </select> <p align="center">County:<br /> <input name="county[]" type="text" id="county[]" /> <p align="center">Contact Email: <br /> <input name="email" type="text" /> <p align="center">Username Desired: <input name="user" type="text" id="user" /> <p align="center">Password Desired: <input name="password" type="text" id="password" /> <p align="center"> <label> <input type="submit" name="submit" id="submit" value="Submit" /> </label> </form> Quote Link to comment Share on other sites More sharing options...
hansman Posted July 21, 2008 Author Share Posted July 21, 2008 any ideas? 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.