We help IT Professionals succeed at work.

simplifing the php code

saul_roldan
saul_roldan asked
on
256 Views
Last Modified: 2013-12-12
Is there another way to simplifing this function:

GetSQLValueString

I dont se it in some php pages. I read that this is just a dreamweaver function.
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
 
 
$colname_content = "-1";
if (isset($_GET['id'])) {
  $colname_content = $_GET['id'];
}
mysql_select_db($database_newWeb, $newWeb);
$query_content = sprintf("SELECT contenido FROM arti_submenu WHERE articulo_id = %s ORDER BY articulo_id ASC", GetSQLValueString($colname_content, "int"));
$content = mysql_query($query_content);
$row_content = mysql_fetch_assoc($content);
//$totalRows_content = mysql_num_rows($content);
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
</head>

Open in new window

Comment
Watch Question

Jason C. LevineDon't talk to me.
CERTIFIED EXPERT

Commented:
Yes, it is just a Dreamweaver function.  It gets created automatically whenever you insert any PHP behavior that passes data around.

It's purpose is to sanitize the input from a form and try to protect you against a PHP or SQL injection attack.  You can remove it (make sure you remove all references to it in the rest of the PHP code) but doing so will cause Dreamweaver to report an error in the Behaviors panel.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Jason C. LevineDon't talk to me.
CERTIFIED EXPERT

Commented:
Simulpost!

Author

Commented:
Yes, it is just a Dreamweaver function.  It gets created automatically whenever you insert any PHP behavior that passes data around.

It's purpose is to sanitize the input from a form and try to protect you against a PHP or SQL injection attack.  You can remove it (make sure you remove all references to it in the rest of the PHP code) but doing so will cause Dreamweaver to report an error in the Behaviors panel.

____________________________________________________

Is there any other way to do the samething with the same results? what other programmer do?

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

You could use a mapped array eg ("text" -> $theValue, "long" -> intval($theValue), "int" -> intval($theValue)) and then call $theValue = ($theValue)?array($theValue):"NULL";

does this give the same protecction and achive the same purpose?
Don't talk to me.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.