Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Apposterfies in the data

Posted on 2003-11-10
Medium Priority
Last Modified: 2013-12-12
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'obrian@footy.com, 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...

Question by:shoaib2000
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
LVL 15

Accepted Solution

JakobA earned 300 total points
ID: 9716697
use the function addslashes just before storing data in the database,
and stripslashes just after taking it out again

regards JakobA
LVL 15

Expert Comment

ID: 9716724
if your html <form command have  method='get'  (or no method specified) it might help to use  method='post'  instead.

Expert Comment

ID: 9718717
$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?
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 9721533

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...


Author Comment

ID: 9721540
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"

Expert Comment

ID: 9722670
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?


Expert Comment

ID: 9729486
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.

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question