Apposterfies in the data

I have a php form, which asks the user to enter their details including email address. Its working fine till someone enter their email address with Apposterfie in it, like   simon', and another problem is if some enter in the interest field "cricket & football" it only saves the "cricket ". are their any PHP functions which are available which i can pass my data to and if there are any Apposterfies or & in it, then the function would ignore it...  

Im just learning PHP so if there are any functions, please also explain how to use that function...

Who is Participating?
JakobAConnect With a Mentor Commented:
use the function addslashes just before storing data in the database,
and stripslashes just after taking it out again

regards JakobA
if your html <form command have  method='get'  (or no method specified) it might help to use  method='post'  instead.
$newString=htmlspecialchars($string); //will also server your purposes, just read in the manual for more information.

If your value is not being passed using quotes - this should be remedied by using the POST method as JakobA said. GET methods for forms are illadvised as they can have serious challenges when trying to get a browser to interpret the character sets properly.

Any more difficulties pertaining to this question?
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

shoaib2000Author Commented:

So if i use addslashes(), does that mean data would be stored in the database with the slashes in it...  is there any way i can make the system ignore these ' & character in a string and store the data in its original form.

Secondly it doesn't work with &, i.e if you have a string "This & that" it doesn't add slash in front of the &.... i have a search field where people type in the search they want, i get the string from the field and use the Sql query to search the database but when someone type in "this & that" it only pick up the "this " bit it ignores everything after the &...

Any ideas...

shoaib2000Author Commented:
Im using the post method in the forms....

this one doesn't work at all....

$string = "your name is o'brian";
echo $newString;

it still prints "your name is o'brian"
so are you wanting to remove apostrafies from the string or add it?
From what it appears - the code is working... Yes?

If not can you be a bit more explicit about what the difficulty actually is?

you can always do:

and that should keep the ' from getting removed or causing trouble...

Is the space reading problem fixed?

JakobA is right.
Only use addslashes on the data just before you insert it.
This will not add the slashes really to the database, it will only make sure the database interprets your data correctly.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.