문제

I have a mysql statement like this:

mysql_query("INSERT INTO movies (comments, description, synopsis)
VALUES ('$_POST["comments"]', '$_POST["desc"]',$_POST["synopsis"])");

very simple and straightforward as you can see. The issue is when I enter special characters to the form, it doesnt insert the data to my table (using phpmyadmin to check directly if it was inserted). for example if i put in comments textarea this value: "this is a comment" this works if I put instead: "what's your name? : John doe is my name" it breaks.I know its because mysql uses the characters... any suggestions on what I should do ?

도움이 되었습니까?

해결책

mysql_query("INSERT INTO movies (comments, description, synopsis) 
VALUES ('".mysql_real_escape_string($_POST["comments"])."', '".mysql_real_escape_string($_POST["desc"])."','".mysql_real_escape_string($_POST["synopsis"])."'"); 

다른 팁

$comments = mysql_real_escape_string($_POST['comments']);
$desc = mysql_real_escape_string($_POST['desc']);
$synopsis = mysql_real_escape_string($_POST['synopsis']);

mysql_query("INSERT INTO movies (comments, description, synopsis)
VALUES ('$comments', '$desc', '$synopsis'");
$comments = mysql_real_escape_string($_POST['comments']);
$desc = mysql_real_escape_string($_POST['desc']);
$synopsis = mysql_real_escape_string($_POST['synopsis']);

mysql_query("INSERT INTO movies (comments, description, synopsis)
VALUES ('$comments', '$desc', '$synopsis'");

For more information google "php addslashes", or look at this page looks explanatory http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top