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
最满意答案
发布的问题对我来说并不是那么清楚,您可以随时切换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 ...
-
开始活动以获得结果(Start Activity for result)[2021-07-03]
发布的问题对我来说并不是那么清楚,您可以随时切换activityForResult并在onActivityResult方法中检查活动结果,检查不同的请求代码。 这是一个代码演示,如何做到: 使用此切换活动: Intent intent = new Intent(this, yourClass.class); intent.putExtras(b); // here startActivityForResult(intent, 2); //put your code along : positive ... -
无法开始活动(Unable to start activity)[2022-06-10]
改变线条: 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活动结果(PrintHelper activity result)[2023-11-13]
看起来像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 ...