Jsonparser Do Not Update Mysql Database
Solution 1:
You're vulnerable to SQL injection attacks, and it's almost guaranteed that the JSON text will contain two of more '
characters, "breaking" your sql query. In essence, you're injecting your own sql query.
You also have no error handling on your queries, and are assuming they succeed. This is very bad. Even if your SQL syntax was 100% perfect, there are far too many OTHER reasons for queries to fail to NOT check for errors:
At bare minimum, you should have
$safe_json = mysql_real_escape_string($_POST['likes']);
$sql = "UPDATE .... WHERE likes='$safe_json' ...";
$result = mysql_query($sql) ordie(mysql_error());
And as a general tip, the mysql_*()
functions have been deprecated as of PHP 5.4. You should consider switching to mysqli, or preferably PDO.
Solution 2:
First of All, Your if condition in JSONParser never executed because,
Your if condition should be,
if(method.equals("POST"))
not a,
if(method == "POST")
second one,
Also, instead of using runOnUiThread
in doInBackground() put your UI updation code in AsyncTask's onPostExecute()
method.
Post a Comment for "Jsonparser Do Not Update Mysql Database"