Jump to content

Recommended Posts

Just like any normal insert statement, just make sure the column type is big enough to house it like TEXT or LONGTEXT etc.

 

INSERT INTO my_table (`id`, `html`) VALUES (1, '<html><head></head><body><p>test<br />another test<script>alert(\'a third test\');</script><br />and a final <a href="http://www.phpfreaks.com">PHPFreakS</a><br /></body></html>');

 

No problem with that at all.

what about punctuation? such as ?!"'@% and such things that are used in php

will they render correctly?

so if my user wants something like "That's my boy! Or is it?"

the punctuation would not effect the mysql query or php code?

It will effect the mysql query as mysql uses the single quotes to seperate out literal data.

 

But luckily for you there is www.php.net/mysql_real_escape_string

 

to correct for that issue, but be aware of www.php.net/get_magic_quotes_gpc

 

You could always use this function (as long as it is mysql and the connection is already started for mysql) to "sanitize" the data for entry into MySQL

 

<?php
/*
   usage: $data = real_escape($_POST['data']);
*/
function real_escape($string) {
       return  get_magic_quotes_gpc()?mysql_real_escape_string(stripslashes ($string)):mysql_real_escape_string($string);
}
?>

 

Which will basically santize the data correctly for entry into a database.

 

And do not worry about the @ % < ? etc, as PHP sees that as literal when pulled from a database, it will not automatically parse it.

right, so say i have the values i want to insert into the database from a form.

there are three values, one that the user does touch as it is hidden and is used for identifying which table row to edit.

the other two have been turned into variables

$title and $description

 

i want to escape the data so it is made safe to insert into a DB. how would i do 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.