I m taking lessons at lynda.com on PHP with MySQL Essential Training . Everything has gone great so far but I got to a point where I needed to do something a little different in order to achieve the same results as the instructor in the videos. Here s his code:
<?php
$query = "INSERT INTO subjects (
menu_name, position, visible
) VALUES (
{$menu_name} , {$position}, {$visible}
)";
?>
当他执行这些职务时,我需要总结一下,在单项引用中可以预见的变数,这样我就认为:
<?php
$query = "INSERT INTO subjects (
menu_name, position, visible
) VALUES (
{$menu_name} , {$position} , {$visible}
)";
?>
It s the only way that I can get the code to work otherwise I get an error that says: "You have an error in your SQL syntax, check the manual that corresponds to your MySQL server version for the right syntax to use..." I understand wrapping $menu_name in single quotes since it represents a string, but the other two represent integer values. Why won t my code execute without the quotes? Is there something I need to change in a config file? Is it considered a better practice to use the the quotes on integers and let SQL do the conversion for me, or should I not need to use those quotes? Any help would be greatly appreciated. If you can t tell by now, I m kind of a noob. Thanks in advance for your help.