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?
 
maxkirConnect With a Mentor Commented:
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
 
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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
 
PadillaAuthor Commented:
Edited text of question.
0
 
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
All Courses

From novice to tech pro — start learning today.