Saving a DomDocument to a Folder on the Server and calling a

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Saving a DomDocument to a Folder on the Server and calling a

Postby rrsimons » Mon Jun 25, 2012 10:14 pm


I am in need of some guidance in solving a couple of issues and want to apologize beforehand for the lengthy summary. Issue one; I am trying to save a filtered mySQL select to a DOMDocument in a folder on the server and it does not seem to be saving the file. The folder attributes is set to 777 so there is not a permissions issue and I have confirmed that a file can be saved to it. Issue two; I need to call a javascript function using a Post Method (i.e., submit button) and I am unsure on how to do that.

URL to a demo page:

This is what I have to populate dataTable and create checkbox in the first column

Syntax: [ Download ] [ Hide ]
<form name="formWellLocators" onsubmit="javascript&#058;load();" method="post">    
      <table align="center" cellpadding="0" cellspacing="0" border="1" id="dataTable" width="100%">
            <th><input name="checkAll" type="checkbox" value="1" onclick="javascript&#058;checkThemAll(this);" /></th>
            <th><input type="text" name="<?=$row['api']?>" value="Filter API" class="search_init" /></th>
                        <th><input type="text" name="<?=$row['state']?>" value="Filter State" class="search_init" /></th>
                        <th><input type="text" name="<?=$row['county']?>" value="Filter County" class="search_init" /></th>
                        <th><input type="text" name="<?=$row['operator']?>" value="Filter Operator" class="search_init" /></th>
                        <th><input type="text" name="<?=$row['spud_date']?>" value="Filter SPUD Date" class="search_init" /></th>
            <th><input type="text" name="<?=$row['lease_well_no']?>" value="Filter Lease/Well No" class="search_init" /></th>
            <th><img src="picts/Check_UnCheck.png" /></th> <!--Check All / Uncheck All Checkbox-->
            <th>SPUD Date</th>
            <th>Lease / Well No</th>
          <!--Start Loop-->
        while ($row = mysql_fetch_array($result)) {
            <td align="center"><input type="checkbox" name="CheckedWell[]" value="<?=$row['id']?>"></td> <!--Individual Check Boxes for the Check All / Uncheck All Button-->
            <td width="120"><?=$row['api']?></td>
            <td align="center"><?=$row['state']?></td>
            <td align="center" width="100"><?=$row['spud_date']?></td>
          <!--End Loop-->

Once the desired checkbox(s) has been selected and the "Refresh Map" button clicked

Syntax: [ Download ] [ Hide ]
<input type="submit" name="CheckedWells" value="Refresh Map" align="left" />

the following code is triggered to create a new DOMDocument and save it as a XML file:

Syntax: [ Download ] [ Hide ]
        if(isset($_POST['CheckedWell'])) {
           foreach($_POST['CheckedWell'] as $item) {
                  $query = ("SELECT * FROM rig_locator WHERE id=$item");
                  $CheckedResult = mysql_query($query);
                  mysql_query($query) or trigger_error("SQL: $sql, ERROR: " . mysql_error(), E_USER_ERROR);
                  // Start XML file, create parent node
                  $dom = new DOMDocument("1.0");
                  $dom->formatOutput = true;
                  $node = $dom->createElement("markers");
                  $parnode = $dom->appendChild($node);   
                  header("Content-type: text/xml");

                  // Iterate through the rows, adding XML nodes for each         
                  while ($row = mysql_fetch_assoc($CheckedResult)){
                        // Add to XML Document Node
                        $node = $dom->createElement("marker");
                        $newnode = $parnode->appendChild($node);
                        $newnode->setAttribute("ID", $row['id']);
                        $newnode->setAttribute("API", $row['api']);
                        $newnode->setAttribute("State", $row['state']);
                        $newnode->setAttribute("County", $row['county']);
                        $newnode->setAttribute("LeaseWellNo", $row['lease_well_no']);
                        $newnode->setAttribute("FieldZone", $row['field_zone']);
                        $newnode->setAttribute("WellBoreType", $row['well_bore_type']);
                        $newnode->setAttribute("Depth", $row['depth']);
                        $newnode->setAttribute("RigNameNo", $row['rig_name_no']);
                        $newnode->setAttribute("SPUD", $row['spud_date']);
                        $newnode->setAttribute("CurrentActivity", $row['current_activity']);
                        $newnode->setAttribute("LAT", $row['lat']);
                        $newnode->setAttribute("LON", $row['lon']);
                  // Save DomDocument as CheckedWells.xml
                  //echo $dom->saveXML() . "\n";                 

and the javascript load() function should be triggered by the on submit event

Syntax: [ Download ] [ Hide ]
<form name="formWellLocators" onsubmit="javascript&#058;load();" method="post">  

Finally the javascript function populates the map with the map markers of the selected wells. Below is the load() function:

Syntax: [ Download ] [ Hide ]
function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(36.77046585083,-98.30557250977), 4);

        GDownloadUrl("xml/CheckedWells.xml", function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
                        var state = markers[i].getAttribute("State");
                        var county = markers[i].getAttribute("County");  
            var operator = markers[i].getAttribute("Operator");
            var field_zone = markers[i].getAttribute("FieldZone");
                        var lease_well_no = markers[i].getAttribute("LeaseWellNo");
                        var api = markers[i].getAttribute("API");
            var well_bore_type = markers[i].getAttribute("WellBoreType");
                        var spud_date = markers[i].getAttribute("SPUD");
            var point = new GLatLng(parseFloat(markers[i].getAttribute("LAT")),
                        var directions = "" + encodeURIComponent(point);
            var marker = createMarker(point, state, county, operator, field_zone, lease_well_no, api, well_bore_type, spud_date, directions);

Can someone assist with solving the DOMDocument not saving problem and guide me on the proper way to call a javascript function via a onsubmit event. I am open to any ideas or suggestions. Thanks in advance for your help and guidance.


User avatar
Forum Newbie
Posts: 6
Joined: Sat Feb 04, 2012 7:29 pm
Location: Deer Park, TX USA

Return to PHP - Code

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 10 guests