homepage Welcome to WebmasterWorld Guest from 54.145.183.169
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
validating form input
need to validate apostrophe
weddingm

5+ Year Member



 
Msg#: 4599198 posted 7:18 am on Aug 4, 2013 (gmt 0)

Hello all,

I am having an issue where if there is an apostrophe in a field, the data is not being accepted into the database and errs out.

Sample:

$field1=mysql_real_escape_string(stripslashes(ucwords(strtolower($_POST['input']))));



insert into database
$insert=mysql_query("INSERT INTO $tablename values (\"\", '$field1', '$field2', '$field3', '$field4')")

Any help appreciated.

 

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4599198 posted 4:49 pm on Aug 4, 2013 (gmt 0)

is it field1 that is giving the error? what is the exact error?

I do find it much easier when I build my queries separate from the mysql_query call, like so

$q = "INSERT INTO $tablename values ('', '$field1', '$field2', '$field3', '$field4')";
echo $q;
$insert = mysql_query($q);

then I can echo the exact thing I am sending and paste that into the command line or phpmyadmin, or whatever you use for mysql, and look at the precise error.

you also should use only single quotes inside your qeury and double around, makes things easier

weddingm

5+ Year Member



 
Msg#: 4599198 posted 5:25 pm on Aug 4, 2013 (gmt 0)

Thanks, the double/single worked.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved