将数据添加到数据库(Adding data to database)
当我尝试使用POST将用户添加到数据库时,会添加一个新用户,但所有字段都是Null。
有帮助吗? 提前谢谢。这是我的源代码:if($_SERVER['REQUEST_METHOD'] == "POST") { // Get data $name = isset($_POST['name']) ; $email = isset($_POST['email']); $password = isset($_POST['password']); $status = isset($_POST['status']); // Insert data into data base $sql = "INSERT INTO users (`name`, `email`, `password`, `status`) VALUES ('$name', '$email', '$password', '$status')"; $qur = mysql_query($sql); if($qur){ $json = array("status" => 1, "msg" => "Done User added!"); }else{ $json = array("status" => 0, "msg" => "Error adding user!"); } }else{ $json = array("status" => 0, "msg" => "Request method not accepted"); } @mysql_close($conn); /* Output header */ header('Content-type: application/json'); echo json_encode($json);
**
When I try to add a user to the database with POST a new user is added but all fields are Null.
Any help guys ? Thank you in advance.This is my source code:if($_SERVER['REQUEST_METHOD'] == "POST") { // Get data $name = isset($_POST['name']) ; $email = isset($_POST['email']); $password = isset($_POST['password']); $status = isset($_POST['status']); // Insert data into data base $sql = "INSERT INTO users (`name`, `email`, `password`, `status`) VALUES ('$name', '$email', '$password', '$status')"; $qur = mysql_query($sql); if($qur){ $json = array("status" => 1, "msg" => "Done User added!"); }else{ $json = array("status" => 0, "msg" => "Error adding user!"); } }else{ $json = array("status" => 0, "msg" => "Request method not accepted"); } @mysql_close($conn); /* Output header */ header('Content-type: application/json'); echo json_encode($json);
**
原文:https://stackoverflow.com/questions/35290169
最满意答案
好吧,我找到了一个解决方案,似乎是一个不起眼的解决方案,但它的工作原理。 在我的研究中,所有问题似乎都针对Honeycumb之后的问题,所以我将API级别更改为11,以获得swapCursor,然后在我的代码上:
Cursor[] cursors = new Cursor[2]; //actual cursor cursors[0] = resourceAdapterCursor.getCursor(); //new cursor returned by async task cursors[1] = result; MergeCursor mergeCursor = new MergeCursor(cursors); if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD){ resourceAdapterCursor.swapCursor(mergeCursor); } else { resourceAdapterCursor.changeCursor(mergeCursor); }
谢谢!
最好的祝福。
罗德里戈Ok, i found a solution, seems an ungly solution, but it works. On my research all the problems seemed to address to an issue after Honeycumb, so i changed the API Level to 11, to get swapCursor available, and then, on my code:
Cursor[] cursors = new Cursor[2]; //actual cursor cursors[0] = resourceAdapterCursor.getCursor(); //new cursor returned by async task cursors[1] = result; MergeCursor mergeCursor = new MergeCursor(cursors); if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD){ resourceAdapterCursor.swapCursor(mergeCursor); } else { resourceAdapterCursor.changeCursor(mergeCursor); }
Thanks!
Best regards.
Rodrigo
相关问答
更多-
Android ListView在notifyDataSetChanged后不刷新(Android ListView not refreshing after notifyDataSetChanged)[2023-11-25]
在ItemFragment查看你的onResume方法: @Override public void onResume() { super.onResume(); items.clear(); items = dbHelper.getItems(); // reload the items from database adapter.notifyDataSetChanged(); } 调用notifyDataSetChanged()之前你刚刚更新的不是适配器的字段priva ... -
好吧,我找到了一个解决方案,似乎是一个不起眼的解决方案,但它的工作原理。 在我的研究中,所有问题似乎都针对Honeycumb之后的问题,所以我将API级别更改为11,以获得swapCursor,然后在我的代码上: Cursor[] cursors = new Cursor[2]; //actual cursor cursors[0] = resourceAdapterCursor.getCursor(); //new cursor returned by async task cur ...
-
你可以按照这个很好的教程 请注意,您需要将List
传递给ArrayAdapter的构造函数。 (可能很简单就是List )这就是我的意思: List values = datasource.getAllYourDataModelClass(); ArrayAdapter adapter = new ArrayAdapter (this ... -
你没有初始化列表(PullToRefreshListView的实例)请在你的oncreate方法的Activity中添加以下行 list = (PullToRefreshListView) findViewById(R.id.yourlistviewid); 然后调用setOnRefreshListener。 还初始化您要使用的其他变量。 You are not initializing list(instance of PullToRefreshListView) please add followin ...
-
弄清楚,答案是在android文档中,这里是链接: http : //developer.android.com/training/basics/fragments/communicating.html Figured it out, the answer was in the android docs, here's the link: http://developer.android.com/training/basics/fragments/communicating.html
-
JSON ListView不刷新(JSON ListView Isn't Refreshing)[2024-02-03]
movieList.clear(); movieList.addAll(movie); adapter.notifyDataSetChanged(); 希望它能解决你的问题, 使用单选按钮时,使用Radio Group改进代码 movieList.clear(); movieList.addAll(movie); adapter.notifyDataSetChanged(); Hope it will solve your problem , Use Radio Group to improve you ... -
我相信你的问题是你没有更新适配器中的实际源列表。 阅读是Java“通过引用”还是“按值传递”? 可能会解释。 解决办法可以是向BowlerAdapter添加一个方法,例如: - public void notifyDatasetChanged(List
newbowlerlist) { bowlersList.clear(); bowlersList.addAll(newbowlerlist); super.notifyDataSetChanged(); } 然后使 ... -
在使用Cursor插入之前和之后没有得到相同的ListView项(Not getting the Same ListView item before and After insert using Cursor)[2021-12-28]
我想用这个: if (result_cursor != null) { CursorDemo cursorDemo = new CursorDemo(ORMLiteActivity.this , result_cursor); cursorDemo.swapCursor(result_cursor); View v = listViewDb.getChildAt(0); ... -
只是调用 listView.startLayoutAnimation(); Just invoke listView.startLayoutAnimation();
-
你正在使用startActivity。 为什么不使用startActivityForResult呢? 这个问题的答案详细说明了如何调用第二个Activity。 一旦返回,您将不得不使用notifyDataSetChanged()调用。 You're using startActivity. Why don't you use startActivityForResult instead? The answer to this question details how you would call the s ...