Jump to content

Magic quotes


jkkenzie

Recommended Posts

magic quotes adds backslashes to my variable which already has backslashes.:

 

function:

 function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}

 

where i add to table:

$insertSQL = sprintf("INSERT INTO events (id, Teasertitle, Teasertxt, Brief, Speaker, Information, Caption, Highres,Venue, Keywords, Enddate, Startdate, Active, Category) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id'], "int"),
                       GetSQLValueString($_POST['Teasertitle'], "text"),
                       GetSQLValueString($_POST['Teasertxt'], "text"),
                       GetSQLValueString($_POST['Brief'], "text"),
                       GetSQLValueString($_POST['Speaker'], "text"),
                       GetSQLValueString($_POST['Information'], "text"),
                       GetSQLValueString($_POST['Caption'], "text"),
                       GetSQLValueString($_POST['Highres'],"file"),
				   GetSQLValueString($_POST['Venue'], "text"),
                       GetSQLValueString($_POST['Keywords'], "text"),
                       GetSQLValueString($_POST['Enddate'], "date"),
                       GetSQLValueString($_POST['Startdate'], "date"),
                       GetSQLValueString(isset($_POST['Active']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['Category'], "text"));

 

 

My GetSQLValueString($_POST['Highres'],"file"), is a file field to pick the location of the file or picture.

 

When i echo the $_POST['Highres'], i get something close to :

C:\\my computer\\xampp\\htdocs\\mywesite\\picture\\djghdfjg.jpg

 

any idea

 

Link to comment
Share on other sites

Perhaps you should read what magic quotes does - http://us2.php.net/magic_quotes

 

POST data is automatically escaped by magic_quotes_pgc and since this (and addslashes()) does not escape all the special characters that can break a query, your code needs to test if magic_quotes_gpc is on, using get_magic_quotes_gpc(), and if it is, you need to strip the slashes and then use mysql_real_escape_string() on the data to escape all of the special characters.

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.