Jump to content

Inserting into database in correct format


dc_jt

Recommended Posts

Hi I am using php and I am looking at the best way to insert into a database and then echo out again in the correct format. I.e Im particularly talking about when adding apostrophes etc. I am also not using magic quotes (as I believe this will be discontinued in PHP6 and my current server has it disabled. I know I can enable it but Im trying to think ahead). Do I remove slashes, add slashes or something else? Ideally I would like to be able to simply echo out the result like <?=$aResult['description']?> without having to add any formatting everytime I echo out.

 

Therefore if I entered "Test test's "test"" for example into a field, what should I do to this before I insert it into the database in order to get the correct format when I output it?

 

Hope that makes sense.

 

Thanks

Link to comment
Share on other sites

It depends on what DBMS you are using. There is the mysql_real_escape_string function for MySQL. The MySQLi and PDO extensions support something called prepared statements, which I personally prefer.

 

Thanks for the reply, I am using PhpMyAdmin. So I would basically do the following before inserting into the database?

 

$_POST = mysql_real_escape_string($_POST)

 

Also, I am using TinyMCE on some fields, does this make any difference or not?

Link to comment
Share on other sites

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.