Delaran Posted May 4, 2007 Share Posted May 4, 2007 Hey guys, I'm new to SQL altogether but have been learning fast. I am seeking some help with my database INSERT command. I have a php page which contains -numerous- options, and the goal of the page is that the person using it will be able to select multiple areas to insert into one field. <td>Seward Park - <input type="checkbox" name="sewardpark" value="Seward Park"> <td>Shilshole - <input type="checkbox" name="test" value="Shilshole"> <td>Shoreline - <input type="checkbox" name="test" value="Shoreline"> <td>Tukwila - <input type="checkbox" name="tukwila" value="Tukwila"> This is just a quick example. For instance, if I wanted to check the boxes for Seward park, Shoreline, and Tukwila, how would I get them all to be entered into one field? ie. ROW1|||ROW2|||ROW3 ID1 DATA Seward Park, Shoreline, Tukwila ID2 DATA Shoreline, Tukwila As of right now I have to specifically reference the name of the city in the POST data, and it does not enter multiples. As you can see I tried to use 'test' as a similar name so that it would see two values that were checked named test. This following query -WORKS-, it just does not send all the checked data to the database, just the first one clicked. My insert statement is as follows (with test as the post data in category): $section = mysql_escape_string($_POST['section']); $category = mysql_escape_string($_POST['test']); $specialty = mysql_escape_string($_POST['specialty']); $query = "INSERT INTO sections (section, category, specialty) VALUES ('".$section."', '".$category."', '".$specialty."')"; mysql_query($query) or die (mysql_error ()); I was thinking if I gave all the checkboxes a shared name, it might work.. but how would I seperate those fields? I'd appreciate any help! Quote Link to comment https://forums.phpfreaks.com/topic/50020-checkboxes-entered-via-mysql/ Share on other sites More sharing options...
suttercain Posted May 8, 2007 Share Posted May 8, 2007 Where are you getting this data from? $section = mysql_escape_string($_POST['section']); $category = mysql_escape_string($_POST['test']); $specialty = mysql_escape_string($_POST['specialty']); Based on your check box names I think you want something like this: <td>Seward Park - <input type="checkbox" name="sewardpark" value="Seward Park"> <td>Shilshole - <input type="checkbox" name="shilshole" value="Shilshole"> <td>Shoreline - <input type="checkbox" name="shoreline" value="Shoreline"> <td>Tukwila - <input type="checkbox" name="tukwila" value="Tukwila"> $vb1 = mysql_escape_string($_POST['sewardpark']); $vb2 = mysql_escape_string($_POST['shilshole']); $vb3 = mysql_escape_string($_POST['shoreline']); $vb4 = mysql_escape_string($_POST['tukwila']); $checklist = "$vb1, $vb2, $vb3, $vb4, Now INSERT $checklist, this should take care of the single cell issue. Quote Link to comment https://forums.phpfreaks.com/topic/50020-checkboxes-entered-via-mysql/#findComment-247837 Share on other sites More sharing options...
mmarif4u Posted May 8, 2007 Share Posted May 8, 2007 mysql_escape_string like: mysql_real_escape_string Quote Link to comment https://forums.phpfreaks.com/topic/50020-checkboxes-entered-via-mysql/#findComment-247843 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.