게시판 만드려고 안드로이드로 정보를 입력받아 디비에 저장하는 것에 도전중입니다.
회원가입에 성공하여 그대로 복붙하여 시도하였는데 에러는 안나지만 디비에 저장이안되네요ㅠㅠ
php파일과 자바코드를 올릴테니 도와주세요ㅠㅠ
<?php
$connect = mysql_connect("localhost", "dahyeon", "비밀번호");
mysql_selectdb("dahyeon");
mysql_query("set names utf8");
$title = $_REQUEST[title];
$content = $_REQUEST[content];
$qry = "insert into board(title, content) values('$title', '$content')";
$result = mysql_query($qry);
?>
php 파일입니다.
import android.app.*;
import android.content.Intent;
import android.os.*;
import android.widget.*;
import android.view.View.*;
import android.view.*;
import java.net.*;
import java.io.*;
public class Sell extends Activity {
EditText w_title, w_content;
String w_id, title, content;
Button write;
boolean reg_success;
@Override
public void onCreate(Bundle SavedInstance){
super.onCreate(SavedInstance);
setContentView(R.layout.sell);
w_title = (EditText)findViewById(R.id.w_title);
w_content = (EditText)findViewById(R.id.w_content);
write= (Button)findViewById(R.id.write);
write.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
lets_reg();
}
});
}
public void lets_reg(){
title = w_title.getText().toString();
content = w_content.getText().toString();
RegTask RegTask = new RegTask ( );
RegTask.execute ();
if( w_title.getText().toString().equals("") || w_content.getText().toString().equals("")) { //이름이나 가격중에 하나라도 입력이 안돼있을때
Toast.makeText(Sell.this,"모든 칸을 입력해주세요.", Toast.LENGTH_SHORT).show();
return;
}
else
Toast.makeText(Sell.this,"작성 완료.", Toast.LENGTH_SHORT).show();
Intent ii = new Intent(getApplicationContext(),MainActivity.class);
startActivity(ii);
finish();
}
private class RegTask extends AsyncTask<String, Void, String> {
String sResult;
@Override
protected String doInBackground(String... sId) {
sResult = "NO";
try{
String body = "title="+title+"&content="+content;
URL u = new URL("http://dahyeon.dothome.co.kr/android/upload.php");
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
huc.setReadTimeout(4000);
huc.setConnectTimeout(4000);
huc.setRequestMethod("POST");
huc.setDoInput(true);
huc.setDoOutput(true);
huc.setRequestProperty("utf-8", "application/x-www-form-urlencoded");
OutputStream os = huc.getOutputStream();
os.write( body.getBytes("utf-8") );
os.flush();
os.close();
BufferedReader is = new BufferedReader(new InputStreamReader(huc.getInputStream(), "UTF-8"));
int ch;
StringBuffer sb = new StringBuffer();
while ((ch = is.read()) != -1) {
sb.append((char) ch);
}
if (is != null){
is.close();
}
sResult = sb.toString();
}
catch (Exception e){
}
return sResult;
}
}
public String respondChecker(String respond){
if (respond.contains("meta")){
if (respond.contains("ERROR")){
String oja = respond.substring(respond.indexOf(">")+1,respond.length());
return oja;
}
else if (respond.length() > 70){
return "ERROR : 정보값 해석불가";
}
else if (respond.contains("SUCCESS")) {
reg_success = true;
String nick = respond.substring(respond.indexOf(">")+1,respond.length());
onRegSuccess();
return nick.trim();
}
else {
return ErrorCatcher(respond);
}
}
else {
return "";
}
}
public String ErrorCatcher(String err){
if (err.contains("id")){
return "ERROR : 이미 존재하는 아이디입니다.";
}
else if (err.contains("mail")){
return "ERROR : 이미 존재하는 이메일입니다";
}
return "ERROR : 해석불가";
}
public void onRegSuccess(){
}
}
자바 코드입니다.ㅠㅠ