insert query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

insert query

Post by gurjit »

hi all,

i have a variable with the following text

Code: Select all

<?php
$school = "Noah's Ark Pre-School";
?>
when i insert into the databse it never goes into the database because of the ' in the text. how can i avoid this....

my insert query is as follows

Code: Select all

<?php
insert into my_table (schoolf) values ('$school')

?>
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Code: Select all

<?php 
$school = addslashes( "Noah's Ark Pre-School" );

// or

$school = mysql_escape_string( "Noah's Ark Pre-School" ); 
?>
mysql_escape_string()

or

addslashes
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post by gurjit »

how can i get rid of the slashes by using the mysql_escape_string function. this stores \ in the database.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

gurjit wrote:how can i get rid of the slashes by using the mysql_escape_string function. this stores \ in the database.
If your seeing slashes you may want to read up on Magic Quotes.
Post Reply