This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Selector with multiples erro

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have this javascript


and this html


I can't record thos options in my table

this is my php script



The script add only id_dia, id_sala in database, not the values of the multiple selector.

any help?
 
Ranch Hand
Posts: 310
18
MS IE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
$_POST['hora'] is an array. You need either separate fields in your database for every array element, or you need to glue all array elements into one string.

Option two is probably what you want, so you can use implode function for that purpose.

To save elements of "hora" multiselect as a single string (with comma separated elements), change your code from



to

 
Gil Carvalho
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Thank you for your help

I put the line but i still not receive the data into my database, check image


The url passed is

dia=5&sala=2&hora%5B%5D=1&hora%5B%5D=2&num=2

But you can see, i have null in all records

So, whats wrong??

imagem.png
[Thumbnail for imagem.png]
database
 
Andrew Polansky
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the late reply.

I didn't look at the code closely, I see that you handle $_POST["hora"] correctly, no need to use implode in this case.

The problem lies here:



In your SQL, you enter data to only three columns: (id_dia, id_sala, id_tempo)

While you want to insert data to four columns:



You have to add the missing column to your SQL. It should be something like:

 
Gil Carvalho
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Thanks
No, this is not the problem

id_ocup is aoto increment

The value $hora is sent from ajax with 1,2,3,4
But when inserted i just have the 1?

The problem is here is this code

 
Andrew Polansky
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, in this case I think the problem lies here:



The first parameter, the 'ssi', says that the values you insert are, in order, String, String, Integer. I guess you store all of your values as strings in your database, because when you try to insert an integer you get a null instead. Try this code to see if it works:

 
Gil Carvalho
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Thanks again....no, that nsert doesn't either but i found something interesting
All the post variable ara correct, with the right values but inside the for check the debug
$hora has 1,2,3,4

when i use the variable
$horas = hora[i]

I have only one value...

Whats wrong?

Thanks
image.png
[Thumbnail for image.png]
 
Andrew Polansky
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm... for some reason $_POST['hora'] is a string, we need to convert it to a proper array.

Because $hora is a string, accessing it as an array like $hora[$i] returns a character of the string that is on the position $i.

Try to use explode function.

Instead of:



try

 
Gil Carvalho
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Thank you again
Now, yes, i have this working
One question more

i put this



But in my function i don't get the response



Why is that?

Thanks again for your help

Best regards
 
Andrew Polansky
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem may lies here:



If in your HTML you don't have the div with ID "ajaxDivOk", then JavaScript code execution will stop due to failure of finding that div.

Check if your HTML has a div with ID "ajaxDivOk", like:



If your HTML has this div, then you may be executing your JavaScript before the DOM is loaded, or more simply saying, before entire HTML is loaded and parsed by the browser. In such case, your code may not be able to find that div, because it is not yet parsed by the browser. If this is the the problem, try wrapping your code in the following code:



This code will ensure that your JavaScript is executed when the entire page gets properly loaded.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic