Jump to content

mySQL with special chars


roeyhaim

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.