syntax error inserting float numbers

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
fayna
Forum Newbie
Posts: 2
Joined: Fri Sep 21, 2007 4:46 am

syntax error inserting float numbers

Post by fayna »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,
I'm trying to execute the following sentence but I get an error:

Code: Select all

$result_id = odbc_prepare ($id_con,"insert into MEDICIONESTRABAJOS (ID, CODIGO, UDS,PVPU,EXPDTE) values ($id_trabajo,'$codigo',$uds,$pvpu, '$expdte')");
Warning: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Line1: syntax error near '12.00'., SQL state 37000 in SQLExecute

The data types are:
ID: int
CODIGO: nvarchar
UDS and PVPU: float
EXPDTE: nvarchar

I obtain UDS and PVPU from a SELECT and the values can be 12.00 or 1225.50 (for example). But if I try doing this:

Code: Select all

$uds = 12.00;
$pvpu = 1225;
I don't get the error and the INSERT is done correctly, so I think the problem is creating the string.

What I'm doing wrong?, Thanks


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post by xpgeek »

Add quote around the values.
fayna
Forum Newbie
Posts: 2
Joined: Fri Sep 21, 2007 4:46 am

Post by fayna »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I add quotes around the values:

[syntax="sql"]insert into MEDICIONESTRABAJOS (ID, CODIGO, UDS,PVPU,EXPDTE) values (658,'E001',12.00, 1225.50, '0157/03')
but I get the warning: quote not closed before string '12.00'


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post by xpgeek »

Quote ALL values.
Post Reply