roeyhaim Posted November 10, 2010 Share Posted November 10, 2010 Hello everyone, how i can insert to the db string that include "$_GET['id']", and i need this as is. in the table i need to see the string $_GET['id'] and not the value. any ideas ? Link to comment https://forums.phpfreaks.com/topic/218333-mysql-with-special-chars/ Share on other sites More sharing options...
simshaun Posted November 10, 2010 Share Posted November 10, 2010 INSERT INTO sometable SET somefield = "$_GET['id']" Why do you need "$_GET['id']" in the database? Link to comment https://forums.phpfreaks.com/topic/218333-mysql-with-special-chars/#findComment-1132806 Share on other sites More sharing options...
Rifts Posted November 10, 2010 Share Posted November 10, 2010 dont do it this way you are completely open to injections please do this $id = $_GET['id']; $id= stripslashes($id); $id= mysql_real_escape_string($id); (" INSERT INTO sometable SET somefield = '$id' ") Link to comment https://forums.phpfreaks.com/topic/218333-mysql-with-special-chars/#findComment-1132807 Share on other sites More sharing options...
simshaun Posted November 10, 2010 Share Posted November 10, 2010 INSERT INTO sometable SET somefield = "$_GET['id']" That is not open to injection, because its not actually retrieving the value of $_GET['id']. Based on my interpretation of the author's wording, that's how he wants it. Link to comment https://forums.phpfreaks.com/topic/218333-mysql-with-special-chars/#findComment-1132815 Share on other sites More sharing options...
kenrbnsn Posted November 11, 2010 Share Posted November 11, 2010 If the OP wants the string "$_GET['id']" to be stored in the DB, this should be used: <?php $str = mysql_real_escape_string("$_GET['id']"); $q = "insert into tbl_name set yourfield = '" . $str . "'"; $rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); ?> Ken Link to comment https://forums.phpfreaks.com/topic/218333-mysql-with-special-chars/#findComment-1132916 Share on other sites More sharing options...
ManiacDan Posted November 11, 2010 Share Posted November 11, 2010 The OP has made it clear that he actually wants THE STRING "$_GET['id']" in his database, NOT the value of that variable. mysql_query("INSERT INTO someTable (somefield) VALUES ('\$_GET['id']')"); This is silly, but it gets what the OP has asked. -Dan Link to comment https://forums.phpfreaks.com/topic/218333-mysql-with-special-chars/#findComment-1133079 Share on other sites More sharing options...
kenrbnsn Posted November 11, 2010 Share Posted November 11, 2010 My solution has an error. This line: <?php $str = mysql_real_escape_string("$_GET['id']"); ?> should be <?php $str = mysql_real_escape_string("\$_GET['id']"); ?> That's what I get for posting when I should be asleep ... Ken Link to comment https://forums.phpfreaks.com/topic/218333-mysql-with-special-chars/#findComment-1133123 Share on other sites More sharing options...
roeyhaim Posted November 11, 2010 Author Share Posted November 11, 2010 thank you all for your help its work perfectly Link to comment https://forums.phpfreaks.com/topic/218333-mysql-with-special-chars/#findComment-1133259 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.