Link to home
Start Free TrialLog in
Avatar of Padilla
Padilla

asked on

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?
Avatar of Padilla
Padilla

ASKER

Edited text of question.
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

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.
Avatar of Padilla

ASKER

Edited text of question.
ASKER CERTIFIED SOLUTION
Avatar of maxkir
maxkir
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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