1

I need help please, I'm having problem inserting a link into my Mysql Database using PHP like this: Example: http://www.textlinkgravity.com/link.php?id=8781&title=Deerpages.co-Free-Online-Business-Directory.html

In Mysql Database upon insert would be: http://www.textlinkgravity.com/link.php?id=8781

My problem is that the & symbol is being cut. I'm using mysql_real_escape_string.

Here is my code:

$link = mysql_real_escape_string($_POST['link']);   
//INSERT NEW ROW
mysql_query("INSERT INTO table (link) VALUES ('$link') ");

My apology for my question cause I don't know how to insert it having complete strings as of this moment.

Thanks to all.

4
  • it works fine for me, and i see "textlinkgravity.com/…" after using mysql_real_escape_string.. have you checked the length of your varchar field? Commented Aug 12, 2012 at 11:45
  • my length is 685 varchar. I'm bit confused now. Commented Aug 12, 2012 at 11:53
  • weird indeed, have you tried echoing out the $link before running the query? Commented Aug 12, 2012 at 12:17
  • yeah it's bit weird. yeah, I'm echoing it and seems okay and complete strings but when you trigger to insert it then it cuts. Commented Aug 12, 2012 at 12:40

1 Answer 1

4

You should encode your URL before inserting

$link = mysql_real_escape_string( urlencode($_POST['link']) ); 
Sign up to request clarification or add additional context in comments.

5 Comments

Hi, after using your suggestion, now after inserting the new row it will look like this. http%3A%2F%2Fwww.textlinkgravity.com%2Flink.php%3Fid%3D8781
That's how it should look. When you're fetching it from DB and displaying you have to decode it again - urldecode
now I've tried to urldecode it but it cuts again. Same result as normal insertion. What to do. I've just discovered the problem.
it works - codepad.viper-7.com/ISSh63 you might want to look into mysql_real_escape_string caused changes or switch to mysqli or PDO
hi thanks for the effort of solving problem, I've just tested your code and it works fine. But, have you tried inserting to mysql database? Please let me know if it's working fine. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.