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("localhos t",$user,$ pass)
{
echo("conectou...");
}
else
{
echo("não conectou...");
exit;
}
if(mysql_select_db("softto tal")
{
echo("database conectado... ");
}
else{ echo("database desconectado...");
exit;
}
if($result = (mysql_query("insert into lista_preco \(codigo,servico,preco,exc ed,cores,f ormatos,de sco,acresc \) values \($codigo,$servico,$preco, $exced,$co res,$forma tos,$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?
After, I wrote a php code as this:
<?php
if(mysql_connect("localhos
{
echo("conectou...");
}
else
{
echo("não conectou...");
exit;
}
if(mysql_select_db("softto
{
echo("database conectado... ");
}
else{ echo("database desconectado...");
exit;
}
if($result = (mysql_query("insert into lista_preco \(codigo,servico,preco,exc
{
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?
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,exc ed,cores,f ormatos,de sco,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
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,exc
"'".$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.
So instead of "\(" and "\)", you can just write "(" and ")".
Arjan.
ASKER
Edited text of question.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER