Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8174507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:28:38+00:00 2026-06-06T22:28:38+00:00

I want to upload an image file into mysql database on Android Mobile Programming,

  • 0

I want to upload an image file into mysql database on Android Mobile Programming, but I’ve some problem with it. Here’s my code:

My code on Eclipse:

private void uploadFile() {
    // TODO Auto-generated method stub
    String nama = getIntent().getStringExtra("user");
    Bundle fieldresults = this.getIntent().getExtras();
    Filepath = fieldresults.getString("bitmap");

    Bitmap bitmapOrg= BitmapFactory.decodeFile(Filepath);
    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, bao);
    byte [] ba = bao.toByteArray();
    String ba1=Base64.encodeBytes(ba);
    ArrayList nameValuePairs = new
    ArrayList();
    nameValuePairs.add(new BasicNameValuePair("image",ba1));
    nameValuePairs.add(new BasicNameValuePair("filename",Filepath));
    nameValuePairs.add(new BasicNameValuePair("username_user",nama));
    try{
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new
    HttpPost("http://10.0.2.2/BloodGlucose/uploadImage.php");
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    is = entity.getContent();
    }catch(Exception e){
    Log.e("log_tag", "Error in http connection "+e.toString());
    }
}

and my PHP code:

    <?php
include_once("koneksi.php");

$username = $_REQUEST['username_user'];


$hasil = mysql_query("select * from login"); 

$base = $_REQUEST['image'];
$filename = $_ReQUEST['filename']
$buffer=base64_decode($base);
$path = "img/".$filename.".jpg";
$handle = fopen($path, 'wb');
$numbytes = fwrite($handle, $buffer);
fclose($handle);
$conn=mysql_connect("localhost","root","");
mysql_select_db("db_bloodglucose");

$sql = "UPDATE login SET file = '" . $path . "' Where username_user = $username;
$r=mysql_query($sql);

?>

The problem is the file didn’t show in my database (mysql), anyone can help me? thanks before

best regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:28:40+00:00Added an answer on June 6, 2026 at 10:28 pm

    Your $sql looks wrong, try:

    $sql = "UPDATE login SET file = '$path' WHERE username_user = '$username'";
    $r = mysql_query($sql);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to upload image file into couchdb using javascript. For this i am
I just implemented an image upload to MySQL via PHP. But i want to
I have a file /tmp/image.jpg that I want to upload into a BLOB field.
I want to store image on mysql database by php as blob type, but
Hallo I want to make an file upload. The script should take the image,
I'm trying to put together an image uploader. I want to upload images into
I have a file upload script that works [finally] but want to have users
Basically I want to upload image and Video file with an html form. Image
I have a component for an image file upload. However, I want to also
I want to save gif type image in mySQL database without post method. <form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.