CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: DBI:
Update & Insert Syntax Problems

 



hancocj
Novice

Nov 4, 2002, 9:57 AM

Post #1 of 5 (5264 views)
Update & Insert Syntax Problems Can't Post

I would like to encode text data when updating and inserting to a mysql table. The reason I want to do this is I get syntax errors for example when the text string contains these characters e.g. ' , ). I guess my question is can this be done with encode? and if so what is the actual syntax? And can the text be decoded with a PHP script? Or is there a better way of getting around this.

Regards,

Jon


Paul
Enthusiast

Nov 4, 2002, 2:50 PM

Post #2 of 5 (5258 views)
Re: [hancocj] Update & Insert Syntax Problems [In reply to] Can't Post

You should be using $dbi->quote


hancocj
Novice

Nov 7, 2002, 3:38 PM

Post #3 of 5 (5251 views)
Re: [RedRum] Update & Insert Syntax Problems [In reply to] Can't Post

I'm sure you're right could you help me get this right. Here is what I have so far but I am still getting a syntax error.

$META_TEXT = $dbh->quote($META_TEXT);
$PARSED_TEXT = $dbh->quote($PARSED_TEXT);

if ( $url ne "" ) {
$dbh->do("update Parent set meta = $META_TEXT, text = $PARSED_TEXT, time = NULL WHERE url=$url") or die "Cannot do: " . $dbh->errstr();
}
else {
$dbh->do( "insert into Parent values ( id, $parent, $META_TEXT, text = $PARSED_TEXT, NULL )") or die "Cannot do: " . $dbh->errstr();
}


erichmusickwc
Novice

Mar 4, 2003, 3:14 PM

Post #4 of 5 (5188 views)
Re: [hancocj] Update & Insert Syntax Problems [In reply to] Can't Post


Code
else {  
$dbh->do( "insert into Parent values ( id, $parent, $META_TEXT, text = $PARSED_TEXT, NULL )") or die "Cannot do: " . $dbh->errstr();
}



Try replacing text = $PARSED_TEXT with just $PARSED_TEXT. When you're doing an insert, you shouldn't put the field name.


Paul
Enthusiast

Mar 5, 2003, 4:51 AM

Post #5 of 5 (5186 views)
Re: [erichmusickwc] Update & Insert Syntax Problems [In reply to] Can't Post

>>
When you're doing an insert, you shouldn't put the field name.
<<

If you want to specify column names you can with:

INSERT INTO Table (Col1, Col2) VALUES ('a','b')

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives