0

im having the following code:

private void setCounter(String counter,String stName){


        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("XXX");


        try{
            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("vCounter",counter));
            nameValuePairs.add(new BasicNameValuePair("StName",stName));

           httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
           HttpResponse response = httpclient.execute(httppost);

        }catch(Exception e){
            Log.e("log_tag", "Error in http connection "+e.toString());
        }
    }


class setCountertoDB extends AsyncTask<Void, Void, Boolean> {//kept


        @Override
        protected Boolean doInBackground(Void... params) {

            setCounter(StringCounter,streetName);
            return null;
        }
    }

PHP file:

<?php 
$con = mysql_connect("XXX","XXX","XXX");
if (!$con)
    {
    die('Could not Connect:'. mysql_error());
    }
mysql_select_db("a6241050_Stpeeds",$con);


mysql_query ("INSERT INTO DBNAME (vCounter) VALUES('".$_REQUEST['vCounter']."') WHERE StName='".$_REQUEST['StName']."'");

mysql_close($con);
?>

the application is running well and there's no error in the logcat, but when i check the database there's no data inserted, please help with that, knowing that i used almost the same code to select values from database and it worked, but it's not working with the insert !

2
  • 2
    As you can read in the docu, MySQL doesn't allow WHERE in an INSERT - what are you trying to do with that anyway? (You'd have known if you had an error check like mysql_query("...") or die(mysql_error());) Commented Dec 8, 2013 at 20:59
  • @kingkero thanks alot, yea the where is not allowed in insert, sorry for that, i'll just try to use the update instead :) Commented Dec 8, 2013 at 21:03

2 Answers 2

3

hI if you have to make a new entry can not use the WHERE:

  mysql_query ("INSERT INTO DBNAME (vCounter) VALUES('".$_REQUEST['vCounter']."')); 
Sign up to request clarification or add additional context in comments.

Comments

1

Try

mysql_query ("UPDATE table_name SET vcounter='".$_REQUEST['vcounter']."'WHERE StName='".$_REQUEST['StName']."'");

This should do the job.

2 Comments

i just did so and it's work out like a charm :), thank alot :)
@Izzo32 happy to know that I could help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.