php - MySqli Real Escape Not Working -


i've been using script upload articles website , done bit of maintainance , when add article on server it's adding slashes text. here code i'm using:

$con = mysqli_connect("localhost","db_username","db_password","db_database");  $title = ucwords($_post['title']); $category = $_post['category']; $article = $_post['article']; $alt = $_post['alt'];  $title = mysqli_real_escape_string($con, $title); $article = mysqli_real_escape_string($con, $article); $alt = mysqli_real_escape_string($con, $alt);  $insert_post_sql = "insert ".$site_id."_articles (id, category, photo, alt, title, article, added, views) values('$id', '$category', '.$extension', '$alt', '$title', '$article', '$added', '$views')"; $insert_post_res = mysqli_query($con, $insert_post_sql); if(mysqli_affected_rows($con)>0){ move_uploaded_file($_files["photo"]["tmp_name"],"$path" . $id . "." . $extension); header("location: ../article.php?id=$id"); exit(); } else{ echo "0"; }; 

so article text looks this: here\'s article\'s text

can tell me why escape isn't working here?

can tell me why escape isn't working here?

mysqli_real_escape_string() possibly doing "escaping" require, "is adding slashes text" not mysqli_real_escape_string() does. don't expect modify code, or add backslashes. escapes chars when adding database.

something other mysqli_real_escape_string() adding slashes text.

mysqli_real_escape_string:

escapes special characters in string use in sql statement, taking account current charset of connection

.

it's adding slashes text when upload here\'s it\'s doing

if have not manually coded in script escape backslash, such using function addslashes(), @zerkms suggested, have magic quotes turned on, "does" escape adding backslash automatically.

determine if magic quotes enabled

if have magic quotes enabled, read this: why not use magic quotes

edit

the suggestion use stripslashes() may make problem "go out of sight", not fix underlying problem, nor attempt address potential issue of using magic quotes, again why not use magic quotes.

just turn off magic quotes, fixing issue, other security concerns, , fact depreciated , shouldn't using in code may not work on newer server or server update.

if have magic quotes enabled, wasting resources magic quotes adding slashes , stripslashes() removing them.

this not fix, "bodge".
if you're happy no worries, @ all, fyi in opinion approach not practice @ all.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -