I write a simple post from java to my php backend.
After I run the script I am getting the output that I am passing in filename, filesize etc..
int filesize=25; String filetype=".txt"; String hash="sdfjksdfhljahe8wr897348957jsdfajlsdhfl48"; String email="sangwan.ritesh@yahoo.in"; String filename="songs.txt"; String urlParameters = "filename="+filename+"&filesize="+filesize+"&filetype="+filetype+"&filehash="+hash+"&email="+email; URL url = new URL("myurl"); HttpURLConnection hp=(HttpURLConnection)url.openConnection(); hp.setDoInput(true); hp.setDoOutput(true); hp.setInstanceFollowRedirects(false); hp.setRequestMethod("POST"); hp.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); hp.setRequestProperty("charset", "utf-8"); hp.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length)); hp.setUseCaches (false); DataOutputStream wr = new DataOutputStream(hp.getOutputStream ()); wr.writeBytes(urlParameters); wr.flush(); String line; BufferedReader reader = new BufferedReader(new InputStreamReader(hp.getInputStream())); line = reader.readLine(); System.out.println(line); wr.close(); reader.close(); hp.disconnect();
The problem is I want to insert these values into my mysql database running on server so I write the following php code.
<?php include('dbc.php'); $filename=$_POST['filename']; $filesize=$_POST['filesize']; $filetype=$_POST['filetype']; echo $POST['email']; $filehash=$_POST['filehash']; $email=$_POST['email']; $query = "INSERT INTO files ( `email`, `file_name`, `file_ext`, `file_size`, 'file_hash') VALUES ( '$email', '$filename', '$filetype', '12584', 'filehash')"; $result=mysqli_query($dbc,$query); if(mysqli_affected_rows($dbc) == 1) { // DO Nothing } echo $_POST['filehash']; echo $_POST['email']; echo $_POST['filename']; echo $_POST['filesize']; echo $_POST['filetype']; ?>
The data is being is posted and I am getting the same back in my java application but data is not being entered in mysql database. I have a table name files with the same columns described above.