4 Replies - 197 Views - Last Post: 22 September 2017 - 09:25 AM

#1 kifle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 20-October 14

Display and upload image in mysql database

Posted 31 August 2017 - 03:56 AM

I tray to store and display image, id ,and name in mysql database my code is work for id and name the image part are empty
how can i solve the problems of the code.
I use mysql version:5.6.35 and php version 7.1.1.
 
<!DCTYPE HTML>
    <HEAD> <h3>Test Form </h3>
 <title> esu </title> </HEAD>
       
                                     
    <BODY>
         
        <FORM NAME = "F1" ACTION = " storinfo.php" enctype="multipart/form-data"  METHID = "GET">
            
             <INPUT TYPE="text"  NAME = "id"  > 
             
             <INPUT TYPE="text"  NAME = "aname"  >   
             
             <INPUT TYPE="file"  NAME = "photo" ID ="photo" >         
            
            <INPUT TYPE="submit" VALUE = "upload" NAME = "submit">

        </FORM>
<?php

    ini_set('display_errors',1);
    error_reporting(E_ALL);
    $con=mysqli_connect("localhost","root","root","android");

    if ($con== false)
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    else{
        $id = $_GET['id'];
        $aname = $_GET['aname'];
    	$photo = $_FILES['photo']['tmp_name'];
        $name = $_FILES['photo']['name']; 
        $photo = file_get_contents('$photo');
        $photo = base64_encode($photo);
        
        $q = "INSERT INTO `image`(`id`, `aname`, `images`) VALUES('$id', '$aname', '$photo')";
        $r = mysqli_query($con, $q);
        
        if($r) {
    	//move_uploaded_file($_FILES['photo']['tmp_name'],"image".$_FILES['photo']['name']);
    	    echo "Records inserted successfully.";
    	}
        else{
    	    echo "ERROR: Could not able to execute $q. " . mysqli_error($con);
        }
    }
    mysqli_close($con);
?>
    </BODY>

</HTML


Is This A Good Question/Topic? 0
  • +

Replies To: Display and upload image in mysql database

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4129
  • View blog
  • Posts: 13,023
  • Joined: 08-June 10

Re: Display and upload image in mysql database

Posted 31 August 2017 - 04:01 AM

$aname doesn't exist. And you're wide open to SQL injection.
Was This Post Helpful? 0
  • +
  • -

#3 kifle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 20-October 14

Re: Display and upload image in mysql database

Posted 31 August 2017 - 06:38 AM

$aname are exist and $photo are doesn't exist.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4129
  • View blog
  • Posts: 13,023
  • Joined: 08-June 10

Re: Display and upload image in mysql database

Posted 31 August 2017 - 06:44 AM

Ok, but I would expect problems (actual URL length limit) sending a file over GET.
Was This Post Helpful? 0
  • +
  • -

#5 kifle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 20-October 14

Re: Display and upload image in mysql database

Posted 22 September 2017 - 09:25 AM

Hi guys, my code is sending a single word while i have written a sentence the problem is the code does not send any thing at all if there is a space is the sentence to a server which will be stored in a MySQL database using PHP.
This is inside my Java file:

@Override protected String doInBackground(String... arg0) { 
    try{
        String ffname =(String) arg[0];
        String llname=(String) arg[1];
        String rrememberMe=(String) arg[2];

       String link = "http://192.168.1:8888/    User/table.php?lname="+ llname+"&          fname="+ffname+"&rememberMe="+ rrememberMe;
      URL url =new URL(link);
      HttpClient client = new     DefaultHttpClient();
request.url =new UR(link);
      HttpResponnse response =     client.execute(request);
}catch (exception e)
{
    e.printStackTrace();
}
return result;
}


I personaly think it is an array problem in the doIn background, is there a way to change it to a string class, thanks in advance.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1