Error: You have an error in your SQL syntax; check the manual that corresponds t

having problems inserting data into the mysql db.
the values from the form are actually being inserted into the bd but the test statement after that is showing the following:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘1’ at line 1

here’s the php code

[php]<?php
include("…/…/lib/conectar.inc");

if(isset($_POST[‘submit’])){
$grava=mysql_query(“INSERT INTO filmes (id,nome,ano,elenco,comentario) VALUES (’’,’$_POST[nome]’,’$_POST[ano]’,’$_POST[elenco]’,’$_POST[comentario]’)”,$conn);

if(!(mysql_query($grava,$conn))){
	die("Error: ".mysql_error());
	}else{
		echo("$_POST[nome] inserido com sucesso.");
		}
	mysql_close($conn);	
		
}

?>[/php]

here’s the html form

[code]

Name:

Year:

Cast:

Comment:

[/code]

any help would be appreciated.
thanks

Change this line:
[php]if(!(mysql_query($grava,$conn))){[/php]

to this:
[php]if($grava === false) {[/php]

The function mysql_query is setting $grava to a boolean value, depicting the success of the query in the function. Hence your if statement needs to check the value of $grava to know whether or not the query was successful.

Sponsor our Newsletter | Privacy Policy | Terms of Service