Jump to content

Is this stupid code?


Or1g1naL

Recommended Posts

function updateNode($node, $nodeID, $childNode, $cnodeValue, $xmlFile){
   $dom = new DOMDocument();                
   $dom->load($xmlFile); 
   $node = $dom->getElementsByTagName($node);	 
 foreach($node as $nodes){
	 if($nodes->getAttribute('id') == $nodeID){
	   $nodes->getElementsByTagName($childNode)->item(0)->nodeValue = $cnodeValue;
  	 }
 }
 $dom->save($xmlFile);	 
}



if($_POST['update'] == 'Update'){
  
updateNode("listing", $_POST['id'], "price", $_POST['price'], $xmlfile);
updateNode("listing", $_POST['id'], "beds", $_POST['beds'], $xmlfile);
updateNode("listing", $_POST['id'], "baths", $_POST['baths'], $xmlfile);
updateNode("listing", $_POST['id'], "sqft", $_POST['sqft'], $xmlfile);
updateNode("listing", $_POST['id'], "year", $_POST['year'], $xmlfile);
updateNode("listing", $_POST['id'], "street", $_POST['street'], $xmlfile);
updateNode("listing", $_POST['id'], "city", $_POST['city'], $xmlfile);
updateNode("listing", $_POST['id'], "state", $_POST['state'], $xmlfile);
updateNode("listing", $_POST['id'], "zip", $_POST['zip'], $xmlfile);

}

 

This is all my handy work and wonder what other more experienced people would do instead.

 

 

Link to comment
Share on other sites

Your function creates nine different objects after execution just for the purpose of editing one file, $xmlfile, You shouldn't put procedural code inside a function unless you require it to be flexible enough for other files, in this example it is redundant.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.