After clicking the delete button, the selected data disappears from the page. It seems to have been deleted, but it will be displayed again after refreshing. After refreshing the data in the database table, the data has not been deleted. Please take a look at my data. What's wrong with the code?
The original routing action is the parameter in the url. This is the line 6 $action error in data.php. Now the error message has been modified, but the data still cannot be deleted from the database. What's going on? Woolen cloth? How should I debug code in php?
After modification:
php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
After modification:
Front page JS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
After modification:
Viewed in Headers in Network, it is displayed as: 200
1 2 3 4 5 6 7 8 |
|
Preview in Network, the original error message is: action in data.php on line 6
1 |
|
View Response in Network, the original error message is: action in data.php on line 6
1 |
|
Using Rest Client to test, the result is 200, but the returned data is still deletion failed! It’s really killing me. I can’t figure out what’s wrong and why it can’t be deleted. Judging from the return information, the del_row() method in PHP may not be executed, right? < br>
What should I do?
Execute the SQL statement in the database: delete from t_users where user_id='1'. The prompt is that the deletion is successful, but the execution is unsuccessful on the page. Is it because the parameters passed back are not received? < /p>
phpcn_u15822017-05-16 13:03:04
To summarize, there are 4 errors above:
The parameters returned by delete can only be obtained using $_GET;
delete The returned parameters must be placed in the URL, not in the body; the parameters in the body are used for query;
SQL statements must be proficient, one wrong step will lead to wrong steps;
To execute a SQL statement in the database to check whether the statement is executed correctly, use Rest Client to test whether the URL request is correct;
The following is my correct code. Although it is poorly written, it can be executed without error.
php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
Front-end JS page:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
Public method, log in to the database:
1 2 3 4 5 6 7 8 9 |
|
PHP中文网2017-05-16 13:03:04
You submitted the request using delete method, so the backend cannot receive parameters using $_GET and $_POST.
The delete parameter should be placed in the url:
1 2 3 4 |
|
迷茫2017-05-16 13:03:04
It should be $userId = $_POST['rowId'];
right
1 |
|
A little more
过去多啦不再A梦2017-05-16 13:03:04
You take action
放在body里了,自然$_GET
就取不到action
了,要用$_POST
。
看你都用了DELETE
方式提交了,不如改成restful
...
PHP中文网2017-05-16 13:03:04
1 |
|
Is there a problem with the sql statement? Print it out when the program is running, copy it to the database and run the test once.
習慣沉默2017-05-16 13:03:04
First print $_GET to see what’s there?
This place of yours is very strange, try changing the dataType to json
The reason for the error is because the action parameter is not found