Hello ppl!
I need help, i'm building a form and processing him by php script. the form consist in 6 fields.
in the php script i've already catch all the variables (i try it to print them and i know i have the values in the correct variables) but i'm not understand why the insert statement didn't work someone could help me?
Here is the php code i'm using to do the insert:
$sql = 'INSERT INTO `Produtos` (`ID`, `Nome`, `Descricao`, `Categoria`, `Preco`, `Num_img`) VALUES ('.$id.','.$nome.','.$descricao.','.$categoria.','.$preco.','.$num_img.');';
What i'm doing wrong?
I've tried to insert values instead of my variables and work! What is worng with my variable?
With the best regards
Hugo Gomes
Inserting Product in database
Moderator: General Moderators
If the last query failed mysql_error() returns a messages that describes the error.
Simplest form:
string literals have to be marked for mysql as well as for php.
TryTo see the difference print both "versions" of $sql.
Simplest form:
Code: Select all
$sql = 'INSERT INTO `Produtos` (`ID`, `Nome`, `Descricao`, `Categoria`, `Preco`, `Num_img`) VALUES ('.$id.','.$nome.','.$descricao.','.$categoria.','.$preco.','.$num_img.');';
mysql_query($sql) or die(mysql_error());Try
Code: Select all
$sql = "INSERT INTO
`Produtos`
(`ID`, `Nome`, `Descricao`, `Categoria`, `Preco`, `Num_img`)
VALUES
('$id','$nome','$descricao','$categoria','$preco','$num_img')
";