Jump to content

Sending array to mysql without square brackets after name


defeated

Recommended Posts

Hi, Here is my problem (one of them anyway).  I have a form that sends job details to a mysql db.  Some of the inputs in this form allow multiple selections for which I add "[]" to the end of the name of the input (eg name="location[]")  which tells php to expect an array.  I then use implode to insert the data into the db as a list separated by commas. This works perfectly.  The problem is that for one of the places where I would use this I cant.  I have field called 'jobtype' that displays a selection list of job types eg, accounting, medical, financial etc.  I then use java to populate a field called 'roles' depending on the first selection. So if accounting is selected in the 'jobtype' field then the 'roles' field is automatically filled with relevant roles like "accounting technician, bookkeeper, tax-accountant, auditor etc".  The trouble is that I need to be able to select several 'roles' and if I use name="roles[]" then the javascript won't work. So what I need is a get out of jail free card ( a way around this problem). I am really new to PHP and haven't an inkling of how to do it.  I am happy with the Javascript and don't want to use PHP for that function since it makes no sense to use a server side script for that function.  I just want to know is there a way I can for example give the field an id other than the name attribute for either the java or php to work from? Heeeellllllppppp!!!!!

Link to comment
Share on other sites

I just want to know is there a way I can for example give the field an id other than the name attribute for either the java or php to work from?

 

Yes, give the field an ID.

 

<select id="someID" name="roles">

 

I am happy with the Javascript and don't want to use PHP for that function since it makes no sense to use a server side script for that function.

 

Sorry, but you are wrong there. It makes a lot of sense to use a server side script - your javascript is worthless if someone has javascript turned off. You should never use javascript exclusively, you should always use it as a supplement to a server-side language. If you don't, you are leaving yourself open to heaps of potential problems.

Link to comment
Share on other sites

;D That's great!!! It took me a while.... a long while but I finally got it to work by adding id='ident' on the form and putting ident in instead of the select name in the javascript.  That way I got to keep the square brackets on the select name and both the java and php are happy with me.  I am delighted!  Now on to the next problem..... but that's a subject for a new post!

Thanks again.

 

BTW... the reason I went with Java over php for the select is that it's a long form and it would have been really messy submitting and resubmitting.... probably beyond me at this stage.... I'm very new to all this. I realise that java has limitations but since this will be an 'in house' form I can ensure that all the computers have java enabled in the browser.  Plus.... it worked  ;)

Link to comment
Share on other sites

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.