Author Topic: Error: You have an error in your SQL syntax; check the manual that corresponds t  (Read 40 times)

Dann

  • Guest
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 Code: [Select]
<?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);
	

	
	
	

	
}
?>


here's the html form

Code: [Select]
<div class="center">
<form action="insert.php" method="post">
<p>Name:<input type="text" name="nome" /></p>
<p>Year:<input type="text" name="ano" /></p>
<p>Cast:<input type="text"  name="elenco" /></p>
<p>Comment:<textarea name="comentario"></textarea></p>
<p><input type="submit" name="submit" value="Send" /></p>
</form>
</div>

any help would be appreciated.
thanks

Smokey PHP

  • Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 518
  • Karma: +5/-0
    • View Profile
Change this line:
PHP Code: [Select]
if(!(mysql_query($grava,$conn))){

to this:
PHP Code: [Select]
if($grava === false) {

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.