Question

Processing checkboxes in variable array to update mysql database

Asked by: jools

Hi All,

I'm having a few issues modifying a booking app.
I'm now working on a form to book multiple resources, the form part is ok but I cant seem to get the right way of processing the check boxes properly.

The user selects a platform type (eg SUN and or DISK) which executes the getsystems.php script to display all the available systems. The user then selects whatever systems are free for use. I then need to process all the checked boxes from the form then update the database using the form options and for each system selected in the reference array (at least thats what I think I need to do...)

Also, assuming the database update is successful I'd then like the form to be closed, it is previously opened with windowopen().
If the database update is not successful then I'd like to display an error message and return to the form.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-04-28 at 14:50:03ID24363589
Tags

php

,

checkbox

,

mysql

,

form

Topics

PHP and Databases

,

Asynchronous Javascript and XML (AJAX)

,

PHP Scripting Language

Participating Experts
3
Points
500
Comments
38

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. SUN A5000 FC-AL Array What do I Need to run this on …
    SUN A5000 FC-AL Array What do I Need to run this on a Intel WIN 2K Platform. I have this array with 14 9.1 GB Drives and Would like to run it on my Tyan 2462 MP Server to learn Fiber Channel. Want to do it the cheapest way without sacrificing Quality.
  2. batch update checkbox fields (PHP-MySQL)
    Hi all, I am looking for a way to batch update checkbox fields values in Mysql database. I have a repeat region with checkboxes and am trying to update checkbox fields in MySQL database. I have tried: <?php $ParamID = "1"; if (isset($HTTP_GET_VARS['checkb...
  3. multiple checkbox mysql search
    Hi I have an array from mulitple checkboxes, a user can select multiple section to be searched in the mysql database, my problem is that I can only display one record at a time even the user has selected multiple selections to be viewed. The field it will be searching is ca...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: mstrelanPosted on 2009-04-28 at 15:20:51ID: 24255727

Hi,

In you html form you need to make a bunch of checkboxes with the name "systems[]" and ids like "systems_as400" and values like "as400".

eg..

--- html code ----
<input type="checkbox" name="systems[]" id="systems_as400" value="as400" /><label for="systems_as400">AS 400</label>
<input type="checkbox" name="systems[]" id="systems_intel" value="intel" /><label for="systems_intel">Intel</label>
 
 
---- php code ----
if (is_array($_POST['systems'])) {
    foreach ($_POST['systems'] as $system) {
        // do something with each system.
    }
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window

 

by: mstrelanPosted on 2009-04-28 at 15:22:08ID: 24255740

Then later on if you need to modify the form you will need to first delete from the db all the systems that are checked before you run the loop above.

 

by: joolsPosted on 2009-04-28 at 15:34:25ID: 24255837

Thanks but I'm not sure thats it....

The systems, SUN, HP, INTEL etc are processed by the getsystems.php from ajax, this script will list all the available systems like; SUN01, SUN02, INTEL01, INTEL02 etc

Each system checkbox is built using the code from getsystems.php and displayed in the main form. Note that systemref will be the names like SUN01, SUN02 etc etc.

   echo "<div class='reference'><input type='checkbox' name='reference[]' id='reference[]' /><a onmouseover=\"Tip('" . $systemtip . "',TITLE,'SYSTEM INFORMATION',TITLEALIGN,'center',SHADOW,'true')\" onmouseout=\"UnTip()\">" . $systemref . "</a></div>";

 

by: mstrelanPosted on 2009-04-28 at 15:41:13ID: 24255892

I'm not sure I understand what the problem is you're having. Which part of the process is failing?

 

by: joolsPosted on 2009-04-28 at 16:01:41ID: 24256024

Sorry, I was hoping I could have explained it better....

I can't seem to process the checkboxes named reference[] built using the getsystems.php script and generate the sql code to insert into the database.

By way of an example, assuming that there are no intel servers currently used and that the INTEL checkbox was selected, the getsystems.php script would return 87 Intel Servers available to be booked. If all these servers, INTEL01 thru INTEL87, are then checked by the user and then the user clicked on Add Booking, I would need the form to be processed and the records added into the database like this;
   insert into test_dates values('INTEL01','2009-04-28','2009-04-28','Quickship','1','ACME PLC','Fred Bloggs','CUS')
   insert into test_dates values('INTEL02','2009-04-28','2009-04-28','Quickship','1','ACME PLC','Fred Bloggs','CUS')
   etc etc...

This is where the other options are taken from the form and repeated for every `insert` command for the database.

It's possible to to create an insert statement where all the values are listed and inserted as one sql statement but I also dont know how to build the insert string in this format either.... this may be a better way of doing this as I then only have to connect and insert to the database once.

   eg/
   insert into test_dates values('INTEL01','2009-04-28','2009-04-28','Quickship','1','ACME PLC','Fred Bloggs','CUS'),('INTEL02','2009-04-28','2009-04-28','Quickship','1','ACME PLC','Fred Bloggs','CUS'),('INTEL03','2009-04-28','2009-04-28','Quickship','1','ACME PLC','Fred Bloggs','CUS')

does this make sense??!

 

by: joolsPosted on 2009-04-30 at 14:12:49ID: 24274484

I'm really stuck with this, I've attached a screen pic of what happens when I select "SUN" from the Additional Systems box and I have selected a number of systems which are currently not booked out.

I have added an alert box to print_r the $_post['reference'] information but it just comes up bank.

The code to print the alert box is included below, it looks OK to me but I'm still relatively new.

One thing I did notice what that if I look at the source code I don't see the check boxes which were generated by the ajax code and getsystems.php.

?>
   <script type 'text/javascript'>alert('<?php print_r($_POST['reference']);?>');</script>
<?php

                                              
1:
2:
3:

Select allOpen in new window

 

by: joolsPosted on 2009-04-30 at 16:02:41ID: 24275191

I've been trying to do a bit of research. I believe some of my problem is ajax not doing a postback of the checkbox options....

This is starting to look like 2 questions, one for getting the postback working and the other for processing the postback data and generating the sql to update the database.

If anyone can confirm my thoughts I'll gladly split the question and ask a related Q for postback.

 

by: joolsPosted on 2009-05-01 at 05:17:09ID: 24278429

Thanks Vee_Mod

 

by: Ray_PaseurPosted on 2009-05-01 at 08:55:23ID: 24280679

@jools: This is annoying but a fact: When a checkbox is not checked, there is NOTHING in the $_POST or $_GET array to indicate its status.  It would have been so easy if the designers of the WWW had given us an indicator like "on" or "off" but that is not the case.

Run this script and experiment with it, and you can see what is afoot.

<?php // RAY_checkboxes.php
error_reporting(E_ALL); // SHOW THE BEHAVIOR OF CHECKBOXES
 
// IF ANYTHING WAS POSTED
if (!empty($_POST["_submit"])) 
{
   echo "<pre>"; var_dump($_POST); echo "</pre> \n";
}
?>
<form method="post">
These checkboxes have names...<br/>
Check or Uncheck Some Boxes Here<br/>
<input name=box1 type="checkbox" value="Box1"><br/>
<input name=box2 type="checkbox" value="Box2"><br/>
<input name=box3 type="checkbox"><br/>
<input name=box4 type="checkbox"><br/>
<br />
These checkboxes are part of the "box" array...<br/>
Check or Uncheck Some Boxes Here<br/>
<input name=box[] type="checkbox" value="ABox1"><br/>
<input name=box[] type="checkbox" value="ABox2"><br/>
<input name=box[] type="checkbox" value="ABox3"><br/>
<input name=box[] type="checkbox" value="ABox4"><br/>
<input type="submit" name="_submit"  value="go" />
</form>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:

Select allOpen in new window

 

by: joolsPosted on 2009-05-01 at 09:26:28ID: 24280975

> When a checkbox is not checked, there is NOTHING in the $_POST or $_GET array to indicate its status.

I get that, I really do. however, when I click on SUN in the Additional Systems box it executes the getsystems.php script and then populates the SUN fieldset with the available SUN systems, when I select a number of SUN systems then select the "Add Booking" button at the bottom of the screen, it does not seem to return any values for the reference[] array.

What I cant get my head round is why after I've checked the SUN-01 ... boxes and clicked on add there seems to be nothing there. It's like the ajax stuff isnt building the page properly and passing the check boxes as part of the form.

I have to admit, I'm really stuck with this at the moment.

I can probably set up a demo on a friendly web site if it helps....

 

by: Ray_PaseurPosted on 2009-05-01 at 09:48:21ID: 24281200

A demo might help and I would be glad to look at it.  Also, you might try something like the code snippet.  Put that in the background script and it will email the contents of $_GET and $_POST to you.  I have not tested it, so beware since I am the King of Typos.  Best, ~Ray

<?php // CAPTURE DATA FROM THE BACKGROUND SCRIPT
 
// START THE OUTPUT BUFFER
ob_start();
 
// GET THE DATA
echo "\nGET: ";
var_dump($_GET);
echo "\nPOST: ";
var_dump($_POST);
 
// CAPTURE THE BUFFERED DATA
$my_text = ob_get_clean();
 
// SEND THE DATA
mail('you@your.org', 'OB DATA', $my_text);

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:

Select allOpen in new window

 

by: joolsPosted on 2009-05-01 at 09:56:42ID: 24281274

I'll see if I can setup a demo for over the next few days....

I'll have a go at your code, not to worry, I'll debug it for you ;-)

 

by: joolsPosted on 2009-05-01 at 15:20:15ID: 24283779

I've copied the form to a web server here; http://www.nutworks.co.uk/allocate/addm.php

If you select one of the servers it should list the hardware available, from that you just select what kit you want booked out then click on the Add button at the bottom it's supposed to add all the resources with the other form data to the database.

any thoughts as to what is (not) happening??

 

by: Ray_PaseurPosted on 2009-05-02 at 15:24:23ID: 24287877

Hi, jools: It would be helpful to add error_reporting(E_ALL) to the action script (the "action script" is the one that processes the data from the "form script") and to look closely at the field called "reference" - it looks like the script has a foreach loop near line 36 that looks at $_POST['reference'] but there is no field in the form named 'reference' - so something may be confused there.

Also I could not find any code that updates a data base.  Can you post that part?

Thanks, ~Ray

 

by: joolsPosted on 2009-05-02 at 16:17:20ID: 24287990

Hi Ray,

Thanks for having a quick look.

The reference field is added by the javascript/ajax stuff when it executes the getsystems.php script. I've attached the java code so you should be able to see this.

So, in summary, addm.php displays the main form you looked at, clicking on SUN/HP etc executes the getsystems.php which extracts the available systems from the database and adds this information to this form using the javascript/ajax stuff in allocate.js.

I've not written the update database part yet, that is what I am stuck on, I need to be able to process the form before I can do that.

Where exactly would I add the error_reporting to? Is it needed in addm.php or getsystems.php or both?

 

by: Ray_PaseurPosted on 2009-05-02 at 16:25:23ID: 24288011

Whenever I am developing or debugging, I would put error_reporting(E_ALL) into every script.  At this point in the application life cycle, you WANT to see the errors.

I think I would also approach this application design a little bit differently.  I do not see a requirement for AJAX.  Instead you can send ALL the data to the page and use onClick() to tell the DOM to reveal or hide the appropriate parts.  That way, you will have everything in the form, even if it is not displayed on the browser window.  And with everything in the form, you will have a fairly straightforward UPDATE statement, and substantially less risk of an "out-of-sync" data base.

 

by: joolsPosted on 2009-05-02 at 23:37:00ID: 24288891

How do I load all the information into the form when I  dont know what is required in the form until the user selects the date range?

 

by: Ray_PaseurPosted on 2009-05-03 at 07:24:06ID: 24289984

I don't know - that's an application design question and I'm not really sure how your application works.  

I was thinking that the AJAX call was needed to get information that could have been known before the page was loaded.  My general strategy would be to send all of the HTML information if possible.  (Things that make it not possible include security or giant data sets or unpredictable factors).  So if the date is one of those unpredictable factors, then you're forced to use AJAX or use two separate pages.

Have you tried to visualize the data with the email-from-background-script yet?

 

by: joolsPosted on 2009-05-03 at 09:13:31ID: 24290318

Thanks for your assistance Ray, it's much appreciated...

I needed to get round having loads of forms so was told I needed to learn ajax.

You've seen the main form, you just enter the criteria then when you select the additional platform the ajax stuff uses the date ranges to find what systems are free and displays this in the checkboxes which the user can then select as they wish.

What I cant get the form to do is to process is this new data, (the check boxes which have the specific systems listed) and return the values for the checkboxes that have been selected once the user clicks on add booking.

I didnt think it was going to be this difficult to process a form!

I have added the email stuff to the getsystems.php script but it returns exactly what I expect it to, the system and the date ranges.... (see below).

I have noticed that if you look at the page source once the form has listed the systems, you don't see the checkboxes for the systems, just the ajax divs!

I've googled and checked literally hundreds of pages and online books but I cant find a way of getting ajax to generate checkboxes then process the new checkbox values. I have to admit, my ajax/php and java skills are somewhat limited.

I still don't know if ajax is capable of doing what I want or if I need to go back to the multiple form approach which will be easier to code but wont be what the user wants from the interface.

Are there any options for ajax I am missing??

GET: array(3) {
  ["system"]=>
  string(3) "SUN"
  ["frm_startdate"]=>
  string(10) "2009-05-03"
  ["frm_enddate"]=>
  string(10) "2009-05-03"
}
 
POST: array(0) {
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window

 

by: Ray_PaseurPosted on 2009-05-03 at 09:31:11ID: 24290381

"Are there any options for ajax I am missing??" -- That has got to be the world's most open-ended question ever! ;-)

At its heart, AJAX is just a way of sending data to a backend script and retrieving the stuff that comes back from the script.  That can be a DIV or something much more interesting.  Depending on the handshake between the browser script and the backend script, it can be really elaborate.

I have to leave this for a while, but let me give you a comment on checkboxes that might be useful.  If the checkboxes in a form are NOT CHECKED, they are not present in $_POST, ie, the key that you would expect would have the name of the checkbox is simply not there (!).  This is different from a text input field, which will be present and empty.

I'll look around and see if I can come up with some examples of how to make this work.  It may take a while, but I'll get something back to you here.

Best, ~Ray

 

by: joolsPosted on 2009-05-03 at 09:46:23ID: 24290426

:-)


>> Depending on the handshake between the browser script and the backend script, it can be really elaborate.
Thats what is worrying me, I dont think my handshake is elaborate enough...

>> If the checkboxes in a form are NOT CHECKED, they are not present in $_POST
Yup, totally understand that! In my case however they are checked, I just cant seem to see the array I assign the values to.

>> I'll look around and see if I can come up with some examples of how to make this work.
...that would be truly marvellous....

While your hunting around, I was wondering... have I explained the way I want the form to work properly? I don't want you spending your time hunting around and it's not quite what I had in mind...

I'll keep hunting as well, I cant give up just yet...

 

by: Ray_PaseurPosted on 2009-05-03 at 12:52:15ID: 24291055

Can't recall where I found this originally, but it is probably attributable to Rasmus Lerdorf of PHP fame.  Read it over and see if it makes sense.  I will try to use it as a basis for a script that will find the checkboxes in a submitted form.

I find a lot of this AJAX stuff a bit of a hype.  Lots of people have
been using similar things long before it became "AJAX".  And it really
isn't as complicated as a lot of people make it out to be.  Here is a
simple example from one of my apps.  
 
/* THE JAVASCRIPT TO CREATE THE AJAX INFRASTRUCTURE */
/* FUNCTION TO CREATE THE BROWSER-DEPENDENT REQUEST OBJECT */
function createRequestObject() 
{
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer")
    {
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else
    {
        ro = new XMLHttpRequest();
    }
    return ro;
}
 
 
/* FUNCTION TO SEND THE REQUEST */
function sendReq(action) 
{
    http.open('get', 'ajaxprocessor.php?action='+action);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
 
 
/* FUNCTION TO HANDLE THE RESPONSE */
function handleResponse()
{
    if(http.readyState == 4)
    {
        var response = http.responseText;
        var update = new Array();
 
        if(response.indexOf('|' != -1))
        {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        }
    }
}
 
 
/* CREATE THE OBJECT */
var http = createRequestObject();
 
/* END OF THE JAVASCRIPT */
 
This creates a request object along with a send request and handle
response function.  So to actually use it, you could include this js in
your page.  Then to make one of these backend requests you would tie it
to something.  Like an onclick event or a straight href like this:
 
<a href="javascript:sendReq('foo')">[Foo]</a>
 
That means that when someone clicks on that link what actually happens
is that a backend request to ajaxprocessor.php?action=foo will be sent.
 
In ajaxprocessor.php you might have something like this:
 
/* THE PHP TO HANDLE THE REQUEST FROM THE FRONT-END SCRIPT */
switch($_GET['action']) 
{
    case 'foo':
      // DO WHATEVER PROCESSING IS APPROPRIATE
      // THEN RETURN A RESPONSE STRING TO handleResponse()
      echo "foo|Foo done";
      break;
      // ETC...
}
 
Now, look at handleResponse.  It parses the "foo|Foo done" string and
splits it on the '|' and uses whatever is before the '|' as the dom
element id in your page and the part after as the new innerHTML of that
element.  That means if you have a div tag like this in your page:
 
<div id="foo">Waiting for Foo</div>
 
Once you click on that link, that will dynamically be changed to:
 
<div id="foo">Foo done</div>
 
That's all there is to it.  Everything else is just building on top of
this.  Replacing my simple response "id|text" syntax with a richer XML
format and making the request much more complicated as well.  Before you
blindly install large "AJAX" libraries, have a go at rolling your own
functionality so you know exactly how it works and you only make it as
complicated as you need.  Often you do not need much more than what I
have shown here.
 
Expanding this approach a bit to send multiple parameters in the
request, for example, would be really simple.  Something like:
 
function sendReqArg(action,arg) 
{
    http.open('get', 'ajaxprocessor.php?action='+action+'&arg='+arg);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
 
And your handleResponse can easily be expanded to do more interesting 
things than just replacing the contents of a div.
 
-Rasmus (Lerdorf?)
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:

Select allOpen in new window

 

by: Ray_PaseurPosted on 2009-05-03 at 14:31:41ID: 24291346

Well, after some searching and testing, here is what I have.

First the backend script.  You may want to activate line 18 just to test.

<?php // RAY_30_second_AJAX_backend.php
error_reporting(E_ALL);
// CAPTURE DATA FROM THE FOREGROUND SCRIPT
 
// START THE OUTPUT BUFFER
ob_start();
 
// GET THE DATA
echo "\nGET: ";
var_dump($_GET);
echo "\nPOST: ";
var_dump($_POST);
 
// CAPTURE THE BUFFERED DATA
$my_text = ob_get_clean();
 
// SEND THE DATA
// mail('you@your.org', 'OB DATA', $my_text);
 
// RETURN THE DATA TO THE FRONTEND SCRIPT
echo "$my_text";

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:

Select allOpen in new window

 

by: Ray_PaseurPosted on 2009-05-03 at 14:34:58ID: 24291356

Now the foreground script.  It handles checkboxes and text input.  If you run it with the background script you will see that the "checked" attribute comes through as true or false.

Not that I have anything against AJAX, but there are a lot of moving parts.  I guess that's why many of my colleagues like jQuery!
http://en.wikipedia.org/wiki/JQuery

Best regards, ~Ray

 

by: Ray_PaseurPosted on 2009-05-03 at 14:35:32ID: 24291359

Foreground script here...

<?php // RAY_31_second_AJAX_frontend.php
error_reporting(E_ALL);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>RAY_31_second_AJAX_frontend.php</title>
 
<script language="Javascript">
function xmlhttpPost(strURL)
{
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest)
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject)
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function()
    {
        if (self.xmlHttpReq.readyState == 4)
        {
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystring());
}
 
function getquerystring()
{
    var form = document.forms['f1'];
    var box_1 = form.box_1.checked;
    var box_2 = form.box_2.checked;
    var words = form.words.value;
    qstr = 'box_1=' + escape(box_1) + '&box_2=' + escape(box_2) + '&words=' + escape(words);  // NOTE NO '?' BEFORE THIS QUERY STRING
    return qstr;
}
 
function updatepage(str)
{
    document.getElementById("result").innerHTML = str;
}
</script>
</head>
<body>
<form name="f1">
Box 1 <input name="box_1" type="checkbox" value="1" /><br/>
Box 2 <input name="box_2" type="checkbox" value="2" /><br/>
Words <input name="words" type="text" value="" />
<input value="Go" type="button" onclick='JavaScript:xmlhttpPost("/RAY_30_second_AJAX_backend.php?getarg=123+ABC")' />
</form>
 
<div id="result">Awaiting Your Input...</div>
 
</body>
</html>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:

Select allOpen in new window

 

by: joolsPosted on 2009-05-04 at 05:46:12ID: 24294456

With all the excitement the power supply on the server has popped it's cloggs and gone to the big used hardware store in the sky.... at least I hope it's the power supply and not the motherboard/cpu :-| in anycase, it's not working....

This will obviously delay things a little until I can get it back up and running again. Nw I have to find my special hammer.

 

by: joolsPosted on 2009-05-04 at 05:47:19ID: 24294462

BTW, with the server down email notifications are also a bit of a problem so I'll get back here as soon as I can :-)

 

by: joolsPosted on 2009-05-11 at 05:19:37ID: 24353679

test server is back up again...

Can you tell me what your functions getquerystr and update page do so I can understand and see if I can implement into my own code.

 

by: joolsPosted on 2009-05-30 at 05:54:21ID: 24508812

Ray,

This project is on hold for a few weeks, I've not forgotton but I've been reassigned to complete an audit.

I hope to get back to this as soon as I can, in the mean time thx for your patience.

 

by: Ray_PaseurPosted on 2009-05-30 at 07:15:43ID: 24509059

OK, Good luck with it, ~Ray

 

by: Ray_PaseurPosted on 2009-07-11 at 13:21:19ID: 24832072

Well, we answered the question, as it morphed along, so I think it is suitable to award points. ~Ray

 

by: angelIIIPosted on 2009-08-03 at 13:44:42ID: 25008469

Ray_Paseur,

  can you help me, by indicating which comments you would accept, using the format:
  http://#a<commentid>

tha
nks,
a3

 

by: Ray_PaseurPosted on 2009-08-03 at 13:48:29ID: 25008493

I think the most generalized answer is the most useful for this Q

Like this?
http://#a<24291055>

Bse
t regards, ~Ray

 

by: joolsPosted on 2009-08-05 at 23:54:57ID: 31575699

Thx, Sorry this took so long. I've not been able to get back to the project. I'm scheduled to get back to this in Sept/Oct but that is way off..

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...