Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/50020-checkboxes-entered-via-mysql/
Share on other sites

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.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.