Maverickb7 Posted April 17, 2007 Share Posted April 17, 2007 I've come across a problem and I wanted to see what everyone would suggest. I'm trying to add an item to my database through a form and have been successful. But if I retry to add say: $location = "The Location's going somewhere"; with this: $query = "INSERT INTO my_details VALUES ('$id','$name','$location)"; it gives me an error because of the single quote character. I was wondering how I could get the code to ignore it. Can I just escape it with / and if so.. hot would I go about adding/removing that from the string because its brought to the query? Quote Link to comment Share on other sites More sharing options...
maxic0 Posted April 17, 2007 Share Posted April 17, 2007 Maybe your getting an error because your missing the last ' after $location Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 17, 2007 Share Posted April 17, 2007 maxic0 is right. also, it isn't necessary, but i think it's important to verifiy which columns will be affected in the query so you know what is happening where at all times. http://w3schools.com/php/php_mysql_insert.asp Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 17, 2007 Share Posted April 17, 2007 change to $query = "INSERT INTO my_details VALUES ('$id','$name','$location')"; Note the last ' before ) and $location = "The Location's going somewhere"; to $location = "The Location's going somewhere"; $location = addslashes($location ); $location = "The Location's going somewhere"; with this: $query = "INSERT INTO my_details VALUES ('$id','$name','$location)"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.