English 中文(简体)
我怎么在我的SQL问询中加上煽动性价值观,而不必用单一字加以总结?
原标题:How do I insert integer values in a MySQL query without having to wrap them in single quotes?

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.

问题回答

检查你的愤怒价值。 如果您的变数没有价值,那么你最终会遇到这样的问题。

INSERT INTO subjects (
         menu_name, position, visible
      ) VALUES (
          menu name , , ,)

如果贵方的价值观是正确的,那么你们的心情就好了。

问题固定下来。

我说,我是个不言而喻的,一个不言而喻的错误正是我所做的。

I was missing an = in a piece of code and that was causing me to get those MySQL syntax errors. Here s the code I fixed:

<p>Visible:
   <input type="radio" name="visible" value="0" /> No
    &nbsp;
   <input type="radio" name="visible" value="1" /> Yes
</p>

最初,当我发现yn子错误时,我没有在价值和“1”之间打上平等标志。

这是一种令人sil笑皆是的错误,但当你发现造成你头痛的错误时,它始终感到好。 在这一进程中,我仍然学到很多东西。 感谢你们的帮助!





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签