Insert query does not work in PHP

0

I have the following query that is not working in PHP, because if you run Sql it does not present any problems.

sql= "INSERT INTO books (ISBN, Authorsname, Title, edition, year, publisher, 
category, quantityinstock, price) VALUES(".$ISBN.",'".$Authorsname."', 
'".$Title."', ".$edition.", ".$year.", '".$publisher."','".$category."', 
".$quantityinstock.",".$price.")"
    
asked by anonymous 20.04.2017 / 05:12

2 answers

1

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

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

Everyone must be enclosed in single quotation marks

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

or

VALUES('$ISBN','$Authorsname', '$Title', '$edition', '$year', '$publisher','$category', '$quantityinstock','$price')"
    
20.04.2017 / 05:21
1
sql= "INSERT INTO 'books' ('ISBN', 'Authorsname', 'Title', 'edition', 'year', 'publisher', 'category', 'quantityinstock', 'price') VALUES('{$ISBN}','{$Authorsname}','{$Title}', '{$edition}', '{$year}', '{$publisher}','{$category}', '{$quantityinstock}','{$price}')";

If this works, there were missing single quotes in some fields .. and between {} it gets a cleaner query!

    
20.04.2017 / 14:25