How Insert Data Into Mysql When Cannot Use the \' Carracter Apostrophe
RegisterLogin
How Insert Data Into Mysql When Cannot Use the \' Carracter Apostrophe
Post Description: How Insert Data Into Mysql When Cannot Use the \' Carracter Apostrophe
Tags: How, Insert, Data, Into, Mysql, When, Cannot, Use, the, \', Carracter, Apostrophe
This Post Was Posted On Feb 29, 2008 By leni #1188
Post Description: How Insert Data Into Mysql When Cannot Use the \' Carracter Apostrophe
Tags: How, Insert, Data, Into, Mysql, When, Cannot, Use, the, \', Carracter, Apostrophe
This Post Was Posted On Feb 29, 2008 By leni #1188
How Insert Data Into Mysql When Cannot Use the \' Carracter Apostrophe by leni
Last week i wrote a php script where it was a form, and once the form was submitted, it would enter the information into my mysql database, but for some reason, whenever the information data contain the apostrophe character (the apostrophe charactor is the one that's next to the enter key on your keyboard. Which is the apostrophe key? its this one: ' )
note: this asumes you are familiar with php, mysql and html.
this is an example of the data to be entered into the database when a user would submit the form with information:
Code:
This is an example of the apostrophe not being inserted into my datase when the user's information is entered
one thing i learned is that if the information was entered with the backlash character infront of the apostrophe it would work, so my input information would look like, it would work:
If i were to try to enter this data into my database with my form, it wouldn't work. Finally, i figured out why it doesn't work. I figured out a PHP function to allow these specials characters into the database using ther INSERT or UPDATE commands.
Code:
This is an example of the apostrophe not being inserted into my datase when the user's information is entered
Notice i basically changed user's[b] to user's[/b]
But i know i couldn't have my visitors have to enter a character everytime they use the apostrophe character.
I found a php function that does the trick, its called the: mysql_real_escape_string()
So to understand the mysql_real_escape_string() function, i will show you how it works in a real example:
Lets say i have a form, where i ask the user's name, once the user submits the form, his name would be entered into a database.
the name of the input variable will be called "user_name" so the HTML code would like something like this:
Code:
<form method="post" action="">
<input type="text" name="user_name" value="wallpaperama's">
<br />
<br />
<input type="submit" name="Submit" value="Submit">
</form>
<input type="text" name="user_name" value="wallpaperama's">
<br />
<br />
<input type="submit" name="Submit" value="Submit">
</form>
In this case, the value of user_name is equal to: wallpaperama's
now when its time for the PHP to process the variable user_name and inster into the data, i would use the mysql_real_escape_string() function to make it work, and this is how i would declare it in the php script
Code:
<?php
$user_name = mysql_real_escape_string ($_POST['user_name']);
?>
$user_name = mysql_real_escape_string ($_POST['user_name']);
?>
Now that the variable $user_name has been declared with the real strings, i can insert it into the database and mysql will take it withoug any problems.
[this post sponsored by:]
mysql_real_escape_string = Escapes special characters in a string for use in a SQL statement
Description
string mysql_real_escape_string ( string unescaped_string [, resource link_identifier] )
if you want more hel on this function, you can visit the official PHP website at: http://www.php.net/manual/en/function.mysql-real-escape-string.php
Thanks and i hope it helps, i tried everywhere to find this, but no one would give me information because i didn't know how to explain it.
leni
Quote:
apostrofi, apostrofy, apostrophy, opostrophy, opostrofy, opostrofi, apostrophey, apostrofe, apastrophy, apastrofy, apastrofi, apastrofie, opastrofy, opastrophy, opastrophe, apostophy, apostophe, aostrophe, apostropeh, spostrophe, zpostrophe, qpostrophe, aoostrophe, alostrophe, apistrophe, aplstrophe, appstrophe, apoetrophe, apoatrophe, apodtrophe, apowtrophe, aposrrophe, aposgrophe, aposyrophe, aposteophe, aposttophe, apostgophe, apostfophe, apostriphe, apostrlphe, apostrpphe, apostroohe, apostrolhe, apostropne, apostropte, apostropge, apostropbe
Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
tech support
#1631 1
but its better to use this instead:
trim(stripslashes($_POST['somedata']))
trim(stripslashes($_POST['somedata']))
Feb 21, 2008 Reply Report abuse
hostman
#1630 2
you can check out this post its good information:
http://www.wallpaperama.com/forums/another-way-to-use-mysql-real-escape-string-instead-trimstripslashes-t5712.html
http://www.wallpaperama.com/forums/another-way-to-use-mysql-real-escape-string-instead-trimstripslashes-t5712.html
Feb 10, 2008 Reply Report abuse
Brandon
#1629 3
thank you!!!!!!!!!!!!
i needed this function very badly!!!!
i needed this function very badly!!!!
Dec 02, 2007 Reply Report abuse
Dave
#1628 4
where does the php code you sugested go. i have tried adding it to a few places and nothing worked.
Sep 13, 2007 Reply Report abuse
Sam
#1627 5
after upgrading from mysql 4.x to 5.x, i spent several hours trying to figure out why i couldn't update or insert any data that included apostrophes. once i found this page, i knew why. now i can go to sleep! thanks a million.
Sep 12, 2007 Reply Report abuse
Eric
#1626 6
i was running into a similar problem. in php, if you have an html form and the user types in an apostrophe in a field and submit the form, php will add a backslash before the apostrophe (i.e., "al's" becomes "al's"). in order to get what the user typed, you need to use stripslashes(), which will remove the backslash that php inserted.
May 21, 2007 Reply Report abuse
Robert McMackin
#1625 7
Thank you very much. I have been looking for this
Feb 09, 2007 Reply Report abuse
Leave Your Comments...
©2011 Webune Forums - Wed Dec 28, 2011 8:04 pm
Powered by: Webune Forums V3
Powered by: Webune Forums V3