Where the error on this code?

I wrote on MySQL server a database called softtotal with a table called lista_preco with this fields: codigo int(4) zerofill not null, servico char(20), preco decimal(6,2), exced decima(6,2) , cores int, formatos char(10), desco int, acresc int.

After, I wrote a php code as this:
<?php
if(mysql_connect("localhost",$user,$pass)
{
echo("conectou...");
}
else
{
echo("não conectou...");
exit;
}

if(mysql_select_db("softtotal")
{
echo("database conectado... ");
}
else{ echo("database desconectado...");
exit;
}
if($result = (mysql_query("insert into lista_preco \(codigo,servico,preco,exced,cores,formatos,desco,acresc\) values \($codigo,$servico,$preco,$exced,$cores,$formatos,$desco,$acresc\)) == false)
{
echo("Error on include data in database  lista_preco");
}
else
{
echo("data was include with success");
}
?>
.....
It return the error message especified on if statement that it have a mysql_query function,  but the sintax of mysql_query is correct. Why does it happen?
PadillaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PadillaAuthor Commented:
Edited text of question.
0
freshmeatCommented:
maybe u should check your data type:
such as char or int?

here i assume all data type r char, so i think u can try to add "'" on the beginning and end of every variable:

if($result = (mysql_query("insert into lista_preco \(codigo,servico,preco,exced,cores,formatos,desco,acresc\) values \("'".$codigo."'",
"'".$servico."'",
"'".$preco."'",
"'".$exced."'",
"'".$cores."'",
"'".$formatos."'",
"'".$desco."'",
"'".$acresc."'"\)) == false){
echo("Error on include data in database  lista_preco");
}

BTW, if the data type is "date", then u should format the data into first
u needn't add "'" to some integal value

hope it can help u

0
aarieCommented:
Maybe another thing. If I'm not mistaken, there's no need to escape the "(".

So instead of "\(" and "\)", you can just write "(" and ")".

Arjan.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

PadillaAuthor Commented:
Edited text of question.
0
maxkirCommented:
It looks you missed closing brackets on line like this:
if(mysql_select_db("softtotal")
{

 
And here:
if ($res = (mysql_query(...) == false )
{

you've miissed one more closing bracket.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
freshmeatCommented:
Padilla, i see the modification of your question:

fields: codigo int(4) zerofill not null, servico char(20), preco decimal(6,2), exced decima(6,2) , cores int, formatos char(10), desco int, acresc int.

ok, now i think my comment is right, your should pay attention to the data whose type is char(20), char(10), u should add "'" on the left and right of those "string"
:)
hope it can solve your problem
and points maybe mine
:D
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.