나는 데이터베이스 MySQL을 만들었고 안드로이드 애플 리케이션의 데이터를 데이터베이스에 보내고 싶지만 그렇게 할 수 없었다. 나는 wamp 서버를 사용하고있다. 여기 안드로이드 애플 리케이션에서 MySQL에 데이터를 삽입 할 수없는 이유
<?php mysql_connect("localhost","cupcake","123456");
mysql_select_db("cindy");
$sql=mysql_query("insert into yang (name)values('".$_REQUEST['i_name']."')");
$r=mysql_query($sql);
if(!$r)echo "Error in query: ".mysql_error();mysql_close();?>
이 내가
--
CREATE TABLE IF NOT EXISTS `yang` (
`name` varchar(100) NOT NULL,
PRIMARY KEY (`name`)
)
을 craeted 한 MySQL의 테이블은 제발 도와주세요 안드로이드
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String result = null;
JSONArray jArray;
InputStream is = null;
StringBuilder sb=null;
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("i_name","aaa"));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/testing.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());
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line="0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n"); }
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}//paring datatry
try {
jArray = new JSONArray(result);
//int[] deal_id=new int[jArray.length()+1];
JSONObject json_data=null;
for(int i=0;i<jArray.length();i++){
json_data = jArray.getJSONObject(i);
}
} catch(JSONException e1){
} catch (ParseException e1) {
e1.printStackTrace(); }
}}
에서 내 자바 파일 : 여기에
내 PHP 코드입니다 .. 감사 ...
그리고 당신은 무엇을 얻습니까? 오류가 있습니까? – Thilo
@ Thilo, 나는 어떤 오류도하지 않았다 ... 내 코드가 작동 할 수있다. 내 테이블에 데이터가 없다. –