首页 \ 问答 \ PHP MySQL INSERT语句语法错误(PHP MySQL INSERT statement syntax error)

PHP MySQL INSERT语句语法错误(PHP MySQL INSERT statement syntax error)

我在使用INSERT语句时遇到问题,并且错误只是说:

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 '' at line 1

这根本没有帮助。 我迄今试过的版本失败了:

mysql_query("INSET INTO `cos` VALUES ('".$_GET['prod']."','".$_GET['page']."')");

[不用说,打印时显示的两个变量显示正确的值]我也尝试过在表名称周围没有任何内容的版本,用'或'表示,真的有一百万个组合,没有任何工作。 甚至没有常量或不同的表格。 它只是不会插入任何东西。 我已经检查了特权(我正在用root登录),并且全部都开启了。

我在两台不同的机器上用相同的服务器(XAMPP 1.7.7)尝试过类似的东西,它可以工作。 我完全困惑! 它会是什么?

感谢您的时间!


I'm having problems with an INSERT statement, and the error only 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 near '' at line 1

It's not helpful at all. The version I have tried so far and failed is:

mysql_query("INSET INTO `cos` VALUES ('".$_GET['prod']."','".$_GET['page']."')");

[needless to say that the two variables when printed show the right values] I've also tried versions with nothing around the table name, with ` or ', a million combinations really and nothing works. Not even with constants or into different tables. It just won't insert anything ever. I've checked the privileges (I'm logging into it with root), and it's all on.

I've tried similar stuff on two different machines with the same server (XAMPP 1.7.7) and it works. I'm completely baffled! What can it be?

Thank you for your time!


原文:https://stackoverflow.com/questions/8786444
更新时间:2023-04-25 08:04

最满意答案

发布的问题对我来说并不是那么清楚,您可以随时切换activityForResult并在onActivityResult方法中检查活动结果,检查不同的请求代码。 这是一个代码演示,如何做到:

使用此切换活动:

Intent intent = new Intent(this, yourClass.class); 
intent.putExtras(b);    // here
startActivityForResult(intent, 2); //put your code along : positive integer

检查此方法的结果

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);

    //could replace it with a switch
    if (requestCode == 1){
        //put your code here
            }
}

被调用的活动不需要知道您的请求代码,但是,如果您想要执行类似的操作,可以通过在intent中传递请求代码来实现,如下所示:

intent.putExtra("requestCode", requestCode); 

因此,访问您切换到的活动类中的intent变量。


The question posted was not so clear to me, You can always switch an activityForResult and check for activity result in onActivityResult method checking different request codes. Here is a code demonstration, how to do it:

Switch activity using this:

Intent intent = new Intent(this, yourClass.class); 
intent.putExtras(b);    // here
startActivityForResult(intent, 2); //put your code along : positive integer

Check for result in this method

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);

    //could replace it with a switch
    if (requestCode == 1){
        //put your code here
            }
}

The called activity does not need to know your requestcode, however, if you want to do something like that, you can do that by passing your request code in intent, like this:

intent.putExtra("requestCode", requestCode); 

Hence, access the intent variable in the activity class you switched onto..

相关问答

更多
  • 尝试 public void onClick(View v) { Intent intent = new Intent(A.this, B.class); A.this.finish(); startActivity(intent); } Try public void onClick(View v) { Intent intent = new Intent(A.this, B.class); A.this.finish(); start ...
  • 我想你可以试试Fragments developer.android.com/guide/components/fragments.html I think you can try Fragments developer.android.com/guide/components/fragments.html
  • 正如所建议的,这是我的答案。 首先,我觉得你的代码实际上是杂乱无章的 - 你应该花一些时间来清理它 - 最重要的是,你应该将大部分代码移到一些辅助函数中。 另外,请摆脱使用SharedPreferences的所有代码 - 我真的不明白为什么你有这个代码。 请参阅下面我建议的更改,希望可以帮助您解决问题: public class MainActivity extends AppCompatActivity { StoreDbHelper db = null; SharedPreferenc ...
  • 发布的问题对我来说并不是那么清楚,您可以随时切换activityForResult并在onActivityResult方法中检查活动结果,检查不同的请求代码。 这是一个代码演示,如何做到: 使用此切换活动: Intent intent = new Intent(this, yourClass.class); intent.putExtras(b); // here startActivityForResult(intent, 2); //put your code along : positive ...
  • 改变线条: bundle2 = getIntent().getExtras(); Log.i("logout - ats token", bundle2.getString("responsedata")); 至 bundle2 = getIntent().getExtras(); if (bundle2 != null) { Log.i("logout - ats token", bundle2.getString("responsedata")); } 您还需要相应地更改URLco ...
  • 您可以使用Intent Extras告诉ResultActivity哪个Activity调用它,并显示相应的结果。 请注意,您还应该对代码进行重新分解,以便在“活动”中不使用静态变量来存储数据,而是可以使用SharedPreferences。 只是为了让你开始,这是你在短期内可以做的: 在FruitQuestion ,您将拥有: Intent in=new Intent(getApplicationContext(),ResultActivity.class); in.putExtra("q ...
  • 有解决方案吗 将您的代码清单中的最后两行放在onActivityResult() ,如Android文档中所述 。 更重要的是,您还需要重写activityB以实际遵循使用setResult()将结果传递回activityA的说明。 Any solution? Put your last two lines from your code listing in onActivityResult(), as is described in the Android documentation. More impo ...
  • 看起来像PrintHelper没有那么灵活来跟踪取消事件。 您可以创建自定义的PrintDocumentAdapter并使用PrintManager打印文档。 在那里你会得到打印完成时被调用的方法,以及它是否被取消。 欲了解更多信息看看这篇文章: https : //github.com/shinobicontrols/bitesize-kitkat/blob/master/PrintShop/PrintShop.md Seems like PrintHelper is not that flexible ...
  • 尝试使用 implements View.OnClickListener 或尝试使用Listener作为匿名类,然后告诉我它是否有效。 注意: 类名应以大写开头,您应该尊重它。 更新: 问题出在其他地方,请确保您的ID正确无误! 并且属于Button 。 Try to use implements View.OnClickListener or try to use Listener as anonymous class and then tell me if it works. Note: class ...
  • 您可以使用AsyncTask 。 将您的请求放在doInBackground() ,完成后,它将转到onPostExecute() 。 这是您可以更新布局/开始另一项活动的地方。 您可以在这里阅读更多内容: http : //developer.android.com/reference/android/os/AsyncTask.html You can use AsyncTask for this. Put your request on doInBackground() and after it fin ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)