Insert query does not work in PHP

Asked

Viewed 206 times

0

I have the following query that is not working in PHP, because I run in SQL does not present any problem.

sql= "INSERT INTO books (ISBN, Authorsname, Title, edition, year, publisher, 
category, quantityinstock, price) VALUES(".$ISBN.",'".$Authorsname."', 
'".$Title."', ".$edition.", ".$year.", '".$publisher."','".$category."', 
".$quantityinstock.",".$price.")"
  • of the one echo $sql; and to see what the form is bringing and tests the sql in the database, also saw that it is missing simple quotes in $edition

  • I thought strings would have to be between '' and "" and integers just between ""

  • Or do so : $sql = "INSERT blabla (colunas) VALUES ('{$variavel1}', '{$variavel2}', '{$variavel3}' )"

  • Thanks Max, you’ve given :)

2 answers

1


You missed following same spelling, the first without single quotes and the second quote with single quotes

".$ISBN." .... ' ". $Authorsname." '

everyone has to be in single quotes

VALUES('".$ISBN."','".$Authorsname."', '".$Title."', '".$edition."', '".$year."', '".$publisher."','".$category."', '".$quantityinstock."','".$price."')"

or

VALUES('$ISBN','$Authorsname', '$Title', '$edition', '$year', '$publisher','$category', '$quantityinstock','$price')"

1

sql= "INSERT INTO `books` (`ISBN`, `Authorsname`, `Title`, `edition`, `year`, `publisher`, `category`, `quantityinstock`, `price`) VALUES('{$ISBN}','{$Authorsname}','{$Title}', '{$edition}', '{$year}', '{$publisher}','{$category}', '{$quantityinstock}','{$price}')";

Test if it works like this, it was missing simple quotes in some fields.. and between {} is a cleaner query!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.