OverMyHead Posted February 19, 2014 Share Posted February 19, 2014 I've searched for a few days to find the help I need. Found it once but like an idiot didn't bookmark it and can't refind it... Struggling to find the right terms to search so if anyone could send me in the right direction I would really appreciate the help. Clearly a novice here but I am trying to learn by building different things. Right now I am building a poll with multiple questions. The plan is to have the MySQL database updated with a number value +1 with every submission to keep a running tally of votes for each option. A couple of the questions have four possible answers but the user is to be limited to picking three of four. Basically pick your favourite three of the following options. I can limit them to three options with javaScript but that doesn't work if the browser has it disabled. If you have a tutorial/example of how to limit options with PHP I would love to take a look! I am also trying to figure out how to in turn to only pass those three values to update the database. Thanks for any help/links you have - online tutorial, example code, better brain for coding logic...! Quote Link to comment Share on other sites More sharing options...
WebStyles Posted February 19, 2014 Share Posted February 19, 2014 Javascript is your best bet to do that, since the selection of 3 (out of the 4) answers is done on the client side (i.e. before he posts the results), and php is a server side language. The 'basic' user almost always has javascript active (or they would not be able to use most of the 'cool' time-wasting sites they frequent, like facebook, twitter, instagram, etc...) Without javascript, your option would be to update/refresh the page after every vote, which is silly and painful for the user. If you still want to have a safeguard for people with disabled javascript, just do both versions, and redirect them accordingly. Quote Link to comment Share on other sites More sharing options...
OverMyHead Posted February 21, 2014 Author Share Posted February 21, 2014 Thanks for the reply. I thought about using javaScript. My thought process was though, if they have javaScript turned off then they could select as many of the answers as they wanted without being restricted. I don't want to worry about the majority, I want to make sure I have the entirety. Especially if I extend this to something where accuracy of results actually matters. What I thought I would do was use javaScript on the user side and when the results were submitted do a double check with php which would return an error if there was one. My issue is though, as a novice, I am not proficient enough to think through how to go about the php part. I can't find anything on line in the form of a tutorial that would help me. I assume there must be something out there and I'm just not using the right search terms to find it. I can't be the first to try to do this. Does my plan above at least make sense if I can figure out the right way to code it? thanks Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 21, 2014 Share Posted February 21, 2014 Your plan is correct. While JS will keep the user from having to deal with a delayed error message from PHP, you should always re-edit your input at the server to prevent hacking. That said, I'm confused by your last statements. Do you not know any php? Or just not ready to put in the work to figure out this problem? Basically I would grab each of the 4 inputs (answers) and then count how many are not empty. If there were too many answers, then I would send back the page (with the previous answers as the values of the html) and an error message advising them to make a change. Don't forget the php manual - an absolutely invaluable resource for php developers of all levels. Quote Link to comment Share on other sites More sharing options...
OverMyHead Posted February 24, 2014 Author Share Posted February 24, 2014 Ok that's cool. Like I said and my username would suggest, I'm a novice with little programming knowledge beyond high level basics. I have lots of ideas I want to do but trying to figure this out as I go is cumbersome. So I find tutorials to help and read forums for like issues because the logic of how to go about things often eludes me. I've spent much of my energies on security in an attempt to reduce the likelihood of being hacked. I am getting there but this isn't a full time gig for me so advancement takes a lot of time. If I am struggling to find tutorial help or like issues in forums, I ask and usually someone that is knowledgeable will send me a link that helps or guide me in the right direction to figure out the challenge in front of me. Thanks for your input, it helps! 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.