Php - trying to paste URLs into MySQL table

I am just trying to insert these objects into a table with php.

$sql = 'INSERT INTO table VALUES( '.$active.' , '.$id.' , '.$time.' , '.$url.' ,"some string" )';

In the above code, the url is: http://www.youtube.com/watch?v=sAYc3gGjYW8

When I leave the url column empty, it works, when I put the url in it, then it does not work, and I get the following error.

"Error: you have an error in the SQL syntax, check the manual that matches the version of your MySQL server for the correct syntax to use next to ': //www.youtube.com/watch? V = sAYc3gGjYW8,' some string ')' in the line 1.

Question:

Why url is not inserted the same way as in a regular string?

Is there some kind of function that I need to execute on url_string before it is accepted by MySQL?

PS - url column is currently VARCHAR (256).

...

+3
5

. mysqli_real_escape_string() - .

, . , , , (124 char , varchar (10), ), SQL-.

:

$safe_url = mysqli_real_escape_string($database_connection_object, $url);

, , - .. "blah blah $some_var foo foo" 'blah blah ' . $some_var . ' foo foo'

+7

mysql_real_escape_string(), , URL , .

$sql = 'INSERT INTO table VALUES( '.$active.' , '.$id.' , '.$time.' , "'.$url.'" ,"some string" )';

, MySQL:

://www.youtube.com/watch?v=sAYc3gGjYW8 ,"some string" )

URL- :)

+3

. mysql_real_escape_string mysqli_real_escape_string. , PDO.

, mysql_*, , , script :

$sql = 'INSERT INTO table VALUES( '.$active.' , '.$id.' , '.$time.' , "'.mysql_real_escape_string($url).'" ,"some string" )';

:

$sql = 'INSERT INTO table VALUES( "'.mysql_real_escape_string($active).'" , "'.mysql_real_escape_string($id).'" , "'.mysql_real_escape_string($time).'" , "'.mysql_real_escape_string($url).'" ,"some string" )';

SQL .

+2

, , - mysql_real_escape_string($string). SQL- , .

+1

$id = $_GET['id'];$name = $_GET['name'];$lat = $_GET['lat'];$long = $_GET['long']; $query = mysql_query("INSERT INTO dbname.tablename ( , , Lat , ) VALUES ('".$id."','".$name."','".$lat."','".$long."')");

-1