473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Query works except when variable has apostrophe in it

Hello,

The query below works if $find is just a regular word with no special characters, and it even works if $find has a "%" in it or a "&".

However, it does not work if $find has an apostrophe in it. Any ideas on how I can change the code to make it work if $find has an apostrophe in it?

Thanks in advance,

John

Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. $find1 = urlencode($find); 
  4. print     "<form action='process.php?find=$find1' method='post'>
  5.         Add site: <input name='site' type='text' size='50'>
  6.         <input type='submit' value='Submit'>
  7.         </form> ";
  8. ?>
Then, on process.php, I have:

Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. $remove_array = array('http://www.', 'http://', 'www.');
  4. $site = str_replace($remove_array, "", $_POST['site']);
  5. mysql_connect("mysqlv10", "username", "password") or die(mysql_error());
  6. mysql_select_db("database") or die(mysql_error());
  7.  
  8. $_GET['find'] = $find;
  9. $_GET['find'] = stripslashes($_GET['find']);
  10. $find = urldecode($find);
  11.  
  12. mysql_query("INSERT INTO `$find` VALUES (NULL, '$site',1,0)");
  13.  
  14.  
  15. ?>
Jun 10 '09 #1
1 2204
Markus
6,050 Expert 4TB
First of all, you are wide open to SQL Injection. Please read up on this to prevent any malicious attacks on your database.

Your problem is directly related to the above, and the article can explain it better than myself.

Check out PDO library (specifically, prepared statements), and mysql_real_escape_string().
Jun 10 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
8
by: Dave | last post by:
Hi all, I've been trying to figure this out for the last day and a half and it has me stumped. I've got a web application that I wrote that keeps track of trading cards I own, and I'm moving it...
13
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to...
7
by: Dave Hopper | last post by:
Hi I posted a question recently regarding problems I am having getting a value from a list box to use in a query. I got a lot of help, for which I thank you and it's nearly working! But I need...
2
by: herlihyboy | last post by:
I have searched and can't find any articles pertaining to this issue... I am filling a dataset using a SqlDataAdapter that was instantiated with a SqlCommand object. When the Fill method is...
2
by: Tom | last post by:
Hi, I have some kind of problems with an apostrophe character ('). I would like to select from DataTable DataRow containing value horses' (with an apostrophe on the end). But when I do it in an...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
7
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM",...
1
by: pretzelboy | last post by:
Hi, I last wrote software 13years ago in the pascal, dbase, clipper days. I have recently built a Ubuntu Box and with C++ (and help from the web) setup a serial barcode reader program using Mysql...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.