954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Insert URL into Mysql db and echo back

I'm trying to create a form where I can type in a piece of news as I would normally type and include links in the form

<a href="www.google.com">google</a>


and have it preserve the formatting and display the link as a link when echoing back.

My problem is that despite a fair amount of trying the above link would be coming back as something like wwww.mywebsite.com/\"www.google.com"\ when I echo the db contents. My code is as follows:

$title= mysql_real_escape_string($_POST[title]);
	$description= mysql_real_escape_string($_POST[description]);
	$article= $_POST[article];

	$sql = "INSERT INTO news (title, description, article)			
			VALUES('$title' ,'$description','$article')";
			
		if(mysql_query($sql, $con))
		{
			echo "<p>The news article was submitted. Return to the <a href='../news.php'>news</a> page";
		}
		else
		{
			echo "Articles submission failed: " . mysql_error();
		}


With the result echoing back by the following:

$result = mysql_query("SELECT * FROM news ORDER BY number DESC");

while($row = mysql_fetch_array($result))
  {
	  echo "<h2>" . $row['title'] . "</h2>";
	  echo "<p>" . nl2br($row['article']) . "</p>";	  
	  echo '<div class="gbutton"><g:plusone></g:plusone></div>';
	  
  }


Any help would be appreciated.

Thx

karl.jackson87
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

try to add slashes instead of real escape

$title= addslashes($_POST[title]);	
$description= addslashes($_POST[description]);
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: