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
https://forums.phpfreaks.com/topic/198194-is-this-stupid-code/
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
https://forums.phpfreaks.com/topic/198194-is-this-stupid-code/#findComment-1039879
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.