0

I have problem to insert image in mysql I get the error

Could not enter data: 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 26( the line of the Photo). I already check the convert from byte[] to string is well and reverse to

here is my code :

 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        yourSelectedImage.compress(Bitmap.CompressFormat.PNG, 0,         outputStream);
        photoDB = outputStream.toByteArray();

pass it throw intent

 String photo =    Base64.encodeToString(getIntent().getByteArrayExtra("photo"), Base64.DEFAULT);
 nameValuePairs.add(new BasicNameValuePair("photo", photo));

then Httppost

 httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse httpResponse = httpClient.execute(httpPost);
            String responseBody = EntityUtils.toString(httpResponse.getEntity());

and then PHP script

$photo = $_POST['photo'];
$photo1=base64_decode($photo);

$result = mysql_query("insert into table(..,..,..,Photo)values(..,..,..,'{$photo1}')");

tuples in mysql table

user1876275
  • 21
  • 2
  • 7
  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jul 14 '15 at 20:09
  • could you please be more precise how I get hte info from android still $_POST ? – user1876275 Jul 14 '15 at 20:15
  • You are vulnerable to [sql injection attacks](http://bobby-tables.com). Fixing that will fix your above problem. – Marc B Jul 14 '15 at 20:18
  • Ok but why it's working when I'm insert ( TEXT and INT value ) but not when it's blob ? – user1876275 Jul 15 '15 at 05:52

0 Answers0