Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

maintenance on Horrid code....dont write it in the first place

Status
Not open for further replies.

theEclipse

Programmer
Dec 27, 1999
1,190
US
I most recently came across some code that blows my mind. Not only is it illogical, inefficient, and a bunch of other ill's but it is ugly. The code accesses a database table that is set up to be a config table, however it is setup sideways (ie. they used no common sense when setting this junk up). Note especially the lack of indenting skills.

(also note....this is some of the more logical code on the website....)

This is also a perfect example of when an idea needs KISSing.
Code:
$sql_select = mysql_query( "select * from ".$prefix."store_config");
// fix for path disclosure
if(!$sql_select){
$home_url = $_SERVER['HTTP_HOST'];
	echo"<h1>MySQL Connection failed</h1>
	<p>Why?</p>
	<p>1. Because you are visiting settings.inc.php directly in your browser. Please return to the home URL [URL unfurl="true"]http://$home_url.</p>[/URL]
	<p>2. Because your database settings could be incorrect or there is a problem with the MySQL engine.</p>";
	exit;
}

						while ($row = mysql_fetch_array($sql_select))
			{
	$site_country=$row["site_country"]; 
      $site_name= $row["site_name"];
	$site_url=$row["site_url"]; 
	$site_url_ssl=$row["site_url_ssl"]; 
      $site_dir=$row["site_dir"];
	$site_language=$row["site_language"];
	$site_currency=$row["site_currency"];
	$site_business=$row["site_business"];
      $site_email=$row["site_email"];
	$site_cookie=$row["site_cookie"];
			$site_tax =$row["site_tax"];
	$bg_colour=$row["bg_colour"];
		$colour_1=$row["colour_1"];
			$colour_2=$row["colour_2"];
			$colour_3=$row["colour_3"];
			$colour_4=$row["colour_4"];
			$routine=$row["routine"];
	$ssl=$row["on_ssl"];
	$date_style=$row["date"];
	$site_phone=$row["site_phone"];
	$site_fax=$row["site_fax"];
	$site_address=$row["site_address"];
	$offmsg=$row["offmsg"];
			$online=$row["online"];
	$sale=$row["sale"];

	$free_ship=$row["free_ship"];
	$freeshipamount=$row["freeshipamount"];
	$minimum_order=$row["minimum_order"];

	$banned_ip=$row["banned_ip"];
$admin_ip=$row["admin_ip"];
$stats_disp=$row["stats_disp"];
$sale_disp=$row["sale_disp"];
		$pop_disp=$row["pop_disp"];
	$spot_disp=$row["spot_disp"];
	$prod_limit=$row["prod_limit"];
	$prod_order=$row["prod_order"];
	$cat_rows=$row["cat_rows"];
	$cat_order=$row["cat_order"];
	$cat_format=$row["cat_format"];
	$cart_thumb=$row["cart_thumb"];
	$refer_url=$row["refer_url"];
					$welcome_note=$row["welcome_note"];
					$collage=$row["collage"];
					$banner1=$row["banner1"];
					$banner2=$row["banner2"];
					$banner3=$row["banner3"];
					$url1=$row["url1"];
	$url2=$row["url2"];
					$url3=$row["url3"];
					$logo=$row["logo"];
					$site_notify=$row["site_notify"];
	$pay_default=$row["pay_default"];
	nl2br($site_address);
				}
 
guess the coder didn't know about the extract() function.

Code:
 extract(mysql_fetch_assoc($sql_select));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top