Hey I am trying to insert data to my sql data base and I cant figure out why it isn't working, when I run the php script on the host alone its working but when I try to do it from the android app it just doesn't do nothing I couldn't find the problem so I thought you guys might help me
p.s its not a connection problem I checked the connection and its fine.
here it the android code:
p.s its not a connection problem I checked the connection and its fine.
here it the android code:
- @override
- protected String doInBackground(String... params) {
- String insertUrl = "http://localhost/insert.php";
- club_name = params[1];
- String publisher_name = params[2];
- String club_contact = params[3];
- String club_location = params[4];
- String club_hours = params[5];
- String club_age = params[6];
- String club_description = params[7];
- try {
- URL url = new URL(insertUrl);
- HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
- httpURLConnection.setRequestMethod("POST");
- httpURLConnection.setDoOutput(true);
- OutputStream outputStream = httpURLConnection.getOutputStream();
- BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
- String data = URLEncoder.encode("age","UTF-8")+"="+URLEncoder.encode(club_name,"UTF-8")+"&"+
- URLEncoder.encode("number","UTF-8")+"="+URLEncoder.encode(publisher_name,"UTF-8");
- // URLEncoder.encode("publisher_phone","UTF-8")+"="+URLEncoder.encode(club_contact,"UTF-8")+"&"+
- // URLEncoder.encode("location","UTF-8")+"="+URLEncoder.encode(club_location,"UTF-8")+"&"+
- // URLEncoder.encode("hour_open","UTF-8")+"="+URLEncoder.encode(club_hours,"UTF-8")+"&"+
- // URLEncoder.encode("age","UTF-8")+"="+URLEncoder.encode(club_age,"UTF-8")+"&"+
- // URLEncoder.encode("description","UTF-8")+"="+URLEncoder.encode(club_description,"UTF-8");
- bufferedWriter.write(data);
- bufferedWriter.flush();
- bufferedWriter.close();
- outputStream.close();
- InputStream inputStream = httpURLConnection.getInputStream();
- inputStream.close();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return "Party has been posted!";
- }
- <?php
- require "connection.php";
- $club_name = $_POST["club_name"];
- $publisher_name = $_POST["publisher_name"];
- $publisher_phone = $_POST["publisher_phone"];
- $location = $_POST["location"];
- $hour_open = $_POST["hour_open"];
- $age = $_POST["age"];
- $description = $_POST["description"];
- $sql = "insert into apps(club_name,publisher_name,publisher_phone,location,hour_open,age,description) values ('$club_name','$publisher_name','$publisher_phone','$location','$hour_open','$age','$description')";
- $query = mysqli_query($conn,$sql);
- ?>
- connection php:
- <?php
- $db_name = "ori";
- $mysql_username = "root";
- $mysql_password = "";
- $server_name = "localhost";
- $conn = mysqli_connect($server_name,$mysql_username,$mysql_password,$db_name);
- if($conn)
- {
- //echo "connects";
- }
- ?>