Jump to content

MySQL Escape String Help


geebo

Recommended Posts

I am using a MySQL DB to store text.  I am using php to echo the text onto a web page.  My apostrophes come out as question marks: "Washington's" = "Washington?s".  I a php newbie, but tried to be a good boy and search for a fix before asking for help.  From what I read, mysql_escape_string is the fix I'm looking for.  Dreamweaver inserted mysql_escape_string code when writing my query, but obviously something's not quite right.  Isn't the following code telling MySQL to handle a ' as a ' ?  THANK YOU!

 

Dreamweaver inserted the following code:

 

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;
}
}

Link to comment
https://forums.phpfreaks.com/topic/121001-mysql-escape-string-help/
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.