JavaScript/MySQL question (sorry 'bout that)

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by LDMartin1959 on November 2, 2013 at 1:16am

This isn't a Drupal related question. Sorry but I'm needing help with a JS/MySQL issue and I've got no other resources available to me. I am not proficient at either PHP or JS so please don't laugh too loud if/when I show my ignorance...! :) I know it's probably something small, simple and obvious to someone who knows what the heck they're doing.

URL's listed at the end of the post.

The company I am doing social media for has a form they are needing updated. The form is hardcoded for the year 2013 and they need it updated for 2014. Seems like it would be a straightforward edit but it fails. As far as I can tell the problem appears to be focused around lines 519-525. First off, I know that the page is getting values from the database because as I make selections in the form the form updates with data from the database. Variable "total" is set to 0 on line 519. The for() loop beginning on line 520 (lines 520-524) SHOULD increment "total" based on the selections made in the form. It works in the 2013 version of the form but when I change the 2013 year to 2014 in the revised form it apparently fails to update the value of "total", resulting in the error if() loop beginning line 525 executing and the error message on line 526 being put to the screen.

HELP!!!

Functional form: https://www.theitsummit.com/2013-sponsorship-and-exhibit-space-applicati...

Source: https://dl.dropboxusercontent.com/u/107754695/sponsorship_form.php

Improperly functioning form: https://www.theitsummit.com/2014-sponsorship-and-exhibit-space-applicati...

Source: https://dl.dropboxusercontent.com/u/107754695/sponsorship_form2014.php

Categories:

Comments

My guess is that there are

Posted by tim042849 on November 2, 2013 at 3:41pm

My guess is that there are others viewing this that are seasoned PHPmongers. I am a PHP noob. However, if you fail to get a solution, I may be of some help. After all, coding is coding, yes? If that is the case, go to tj49.com click the contact tab and send me your email or phone number or other method of contact. I wouldn't recommend that you post any of your contact info in this site as it is probably pretty public.

Having said that I bet that the drupal veterans in the group can help you, if their not out having too much fun this weekend...

regards
tim

Drupal Noob (since 2012)
Coder since 1987 - Web Coder since 1996
akwebsoft.com - tj49.com

Weekend...? I've heard that

Posted by LDMartin1959 on November 2, 2013 at 5:19pm

Weekend...? I've heard that term. Not sure what it is exactly.

I googled it. Actually, I

Posted by tim042849 on November 2, 2013 at 6:10pm

I googled it. Actually, I can't ever remember working a Monday-Friday 8 hr. a day week.

Drupal Noob (since 2012)
Coder since 1987 - Web Coder since 1996
akwebsoft.com - tj49.com

Quick suggestions

Posted by tehbmar on November 2, 2013 at 8:59pm

Do a quick diff on the 2013 and 2014 files to makes sure all the lines you change are actually what you want to change (helps you verify you didn't turn "%2013%" into "2014%". You can do this with linux tools like diff http://linux.about.com/library/cmd/blcmdl1_diff.htm
or use an online version http://www.diffchecker.com/
oorrr if you manage your code with git use "git diff [commmit hash before edits]"

Could we also see your PHP error log to see if there are any errors?

As for lines 519-525 and so on, those lines are actually Javascript, this file is pretty messy confusing.

Also there is a HUGE issue I see here..

The code uses mysql_query to insert POST data directly into the database at lines 39-40 without sanitizing it. This could easily result it someone dropping all of your tables, inserting data into other tables, malforming data, etc.

Here is a quick little article on it. http://www.dreamhost.com/dreamscape/2013/05/29/part-2-of-php-security-us...

Where I would start is making sure all of the queries at the top are actually returning data. If that is true than work your way though everything else. When I debug on weird issues I just start at the source until something stops me.

Hope this helps.

I double checked and the only

Posted by LDMartin1959 on November 3, 2013 at 2:47am

I double checked and the only difference is the replacement of the string "2013" with the string "2014". I used a standard search/replace to accomplish it and have double checked it.

Error log is rather slim, but here it is:

[02-Nov-2013 10:32:51 America/Chicago] PHP Fatal error: Call to undefined function wp_title() in /mnt/stor11-wc2-dfw1/504042/www.theitsummit.com/web/content/wp-content/themes/theitsummit/index.php on line 24
[02-Nov-2013 19:26:24 UTC] PHP Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /mnt/stor11-wc2-dfw1/504042/www.theitsummit.com/web/content/wp-content/themes/theitsummit/denver2012registration.php on line 26
[02-Nov-2013 19:26:29 UTC] PHP Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /mnt/stor11-wc2-dfw1/504042/www.theitsummit.com/web/content/wp-content/themes/theitsummit/denver2012registration.php on line 26
[02-Nov-2013 17:08:15 America/Chicago] PHP Fatal error: Call to undefined function wp_title() in /mnt/stor11-wc2-dfw1/504042/www.theitsummit.com/web/content/wp-content/themes/theitsummit/index.php on line 24
[02-Nov-2013 23:03:21 UTC] PHP Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /mnt/stor11-wc2-dfw1/504042/www.theitsummit.com/web/content/wp-content/themes/theitsummit/denver2012registration.php on line 26

This is the log as it exists after I ran a test submission so anything that would have shown up in the log should have been there, but I see nothing that corresponds to the time I did the test (6:30pm/Local).

Yes, those lines in question are JS and yes, I'm not surprised that it is a mess. This entire site is a mess.

As far as no sanitization...again, I'm not surprised. Th people who did the site...well, the less said about them the better.

As for the queries, they do appear to be working, inasmuch as when I make a selection (sponsorship, booths, scanners) the queries return values and update the form data.

Update: I have pinpointed the

Posted by LDMartin1959 on November 4, 2013 at 7:45pm

Update: I have pinpointed the problem...sorta. I still need some help from someone knowledgeable in JS.

The change of date from 2013 to 2014 appears to me to be a red herring since all that was being done with the date was pulling values from the database and stuffing them into a arrays ($event_query, $evt_result, $evt_result1) for the purpose of creating the options presented in the form. The JS then evaluates and validates the form options to ensure that all the required information is present before sending the information via email.

The validation is failing here:

 var total=0;
 for(var i=0;i<frm.chk_event_select.length;i++){
 if(frm.chk_event_select[i].checked) {
 total++;
 }
 }
 if( total == 0 ) {
 str+="Select Any one Event.\n";
 }
 zip_val=new Array();
 event_val=new Array();
 for(var i=0;i<frm.chk_event_select.length;i++){
 if(frm.chk_event_select[i].checked==true) {
 zip_val[i]=frm.chk_event_select[i].value;
 event_val[i]=frm.hidden_name[i].value;
 }
 else{
 zip_val[i]="";
 event_val[i]="";
 }
 }
 for(k=0;k<zip_val.length;k++){
 if(zip_val[k]!=""){
 if($('#sel_sponsor_'+zip_val[k]).val()=="")
 {
 str+=event_val[k]+" Select Your Sponsorship.\n";
 }
 if($('#sel_booths_'+zip_val[k]).val()=="")
 {
 str+=event_val[k]+" Number of Booths.\n";
 }
 }
 }

This is supposed to get a value from the form:

But it isn't. Just don't know why since the same code worked fine before. I do know two additional details:

If I change :

 if( total == 0 ) {
 str+="Select Any one Event.\n";

to:

 if( total == 0 ) {
 alert(frm.hk_event_select.length)
 str+="Select Any one Event.\n";

I get an undefined error in the alert and the submission fails.

If I change it to:

 if( total == 0 ) {
 alert(chk_event_select.length)
 str+="Select Any one Event.\n";

submission goes through but then the validation fails to block the submission when none of the required event options on the form are selected.

???????

Got some help from a (sorta)

Posted by LDMartin1959 on November 5, 2013 at 1:58pm

Got some help from a (sorta) former schoolmate. Turns out (at least as I understand him) that JS has a quirk: an array with only one value in it is NOT treated as an array. :(

Awesome that you were able to

Posted by tehbmar on November 5, 2013 at 5:13pm

Awesome that you were able to solve this. And I didn't know about that javascript array quirk. Thanks for the info!

JSLint recommended

Posted by tim042849 on November 5, 2013 at 7:17pm

I haven't been following this thread since Brandon jumped in on the PHP issues, and didn't take the time to analyze the javascript, which I know a little about. I took the plunge a couple of years ago and started migrating all of my javascript code to be JSLint compliant. I hated it at first because JSLint is very picky and may seen unnecessarily, but I have been happy with the results. Unfortunately, I don't think that JSLint catches all of the Internet Explorer "gotchas", but it does catch unintentional global variables - which has created real headaches for me in the past. Example

x = 1; // Bad! Bad - now x is unintentionally global in scope and may have overwritten another x which was meant to be global
var x = 1; // Good! now scope is under control

Drupal Noob (since 2012)
Coder since 1987 - Web Coder since 1996
akwebsoft.com - tj49.com

Alaska Drupal Users Group

Group categories

Location

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /