Solved

Apposterfies in the data

Posted on 2003-11-10
7
460 Views
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...

Thanks
0
Comment
Question by:shoaib2000
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 15

Accepted Solution

by:
JakobA earned 100 total points
ID: 9716697
use the function addslashes just before storing data in the database,
and stripslashes just after taking it out again
http://dk2.php.net/manual/en/function.addslashes.php

regards JakobA
0
 
LVL 15

Expert Comment

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

Expert Comment

by:red010knight
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?
Red010Knight
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:shoaib2000
ID: 9721533
Hi

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

Thanks
0
 

Author Comment

by:shoaib2000
ID: 9721540
Im using the post method in the forms....

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

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

it still prints "your name is o'brian"
0
 
LVL 3

Expert Comment

by:red010knight
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:
$newString=addslashes(htmlspecialchars($string));

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

Is the space reading problem fixed?

Red010Knight
0
 
LVL 6

Expert Comment

by:DoppyNL
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Echo images using file system 2 32
.php tree directory? 5 56
Calculating number of days between two dates 7 32
How can I echo a PHP variable in AJAX function? 7 35
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now