jkkenzie Posted October 18, 2008 Share Posted October 18, 2008 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 https://forums.phpfreaks.com/topic/128959-magic-quotes/ Share on other sites More sharing options...
wildteen88 Posted October 18, 2008 Share Posted October 18, 2008 That path is fine. If you changed the \\ to \ you may exprience strange results/errors. Link to comment https://forums.phpfreaks.com/topic/128959-magic-quotes/#findComment-668571 Share on other sites More sharing options...
CroNiX Posted October 18, 2008 Share Posted October 18, 2008 You should really be using mysql_real_escape_string() instead of addslashes(). Link to comment https://forums.phpfreaks.com/topic/128959-magic-quotes/#findComment-668636 Share on other sites More sharing options...
jkkenzie Posted October 20, 2008 Author Share Posted October 20, 2008 The mysql_real_escape_string() did not work, the same error. how can \\ be ok?? Or i just omit magic quotes, because it is not working well? Thanks Joseph Link to comment https://forums.phpfreaks.com/topic/128959-magic-quotes/#findComment-669964 Share on other sites More sharing options...
kenrbnsn Posted October 20, 2008 Share Posted October 20, 2008 Change your paths to use "/" instead of "\". Using a forward slash will work in PHP on Windows and then you don't run into that problem. Ken Link to comment https://forums.phpfreaks.com/topic/128959-magic-quotes/#findComment-669978 Share on other sites More sharing options...
jkkenzie Posted October 21, 2008 Author Share Posted October 21, 2008 I have realised that the problem is not with magic quotes. It is my POST that does this. I have no idea what causes the slashes to be added.?? Any help Link to comment https://forums.phpfreaks.com/topic/128959-magic-quotes/#findComment-670807 Share on other sites More sharing options...
PFMaBiSmAd Posted October 21, 2008 Share Posted October 21, 2008 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 https://forums.phpfreaks.com/topic/128959-magic-quotes/#findComment-670810 Share on other sites More sharing options...
jkkenzie Posted October 22, 2008 Author Share Posted October 22, 2008 When i post from my form a value = something "c:\my computer\my pictures\me.jpg" the value when echoed becomes "c:\\my computer\\my pictures\\me.jpg", can magic quotes be used here to get "c:\my computer\my pictures\me.jpg" as the posted value?? Link to comment https://forums.phpfreaks.com/topic/128959-magic-quotes/#findComment-671530 Share on other sites More sharing options...
MasterACE14 Posted October 22, 2008 Share Posted October 22, 2008 you might be able to use stripslashes(); Link to comment https://forums.phpfreaks.com/topic/128959-magic-quotes/#findComment-671531 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.