Jump to content

Recommended Posts

yes, but you will want to do it like this:

 

$mylink = "<a href='mysite.com?title=thanks'>click here</a>";
$sql = "INSERT INTO table_name ('link') VALUES ('".mysql_real_escape_string($mylink)."')";
mysql_query($sql) or die(mysql_error());

 

$result = mysql_query("SELECT * FROM table_name");
$row = mysql_fetch_array($result);
echo $row['link'];

mysql_real_escape_string() preps a string to be inserted into a MySQL DB. let's take your example for instance...the following:

$mylink = "<a href='mysite.com?title=thanks'>click here</a>";
$sql = "INSERT INTO table_name ('link') VALUES ('$mylink')";
echo $sql;

will produce:

INSERT INTO table_name ('link') VALUES ('<a href='mysite.com?title=thanks'>click here</a>')

but that is no good, cus you can't have single quotes inside single quotes. mysql_real_escape_string() adds slashes in front of any needed characters. the slashes don't stay with the string in the DB, they are just to escape it for the query. when you select the data back out, it won't have the extra slashes in it

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.