2015-07-20 161 views
-2

我拥有将我的应用程序链接到我的sql数据库的所有代码logcat中没有错误,应用程序不崩溃,并且在“数据输入”的吐司消息在成功出现所有捕获条款,但在数据库表中没有任何类型的数据输入。在mysql数据库中没有输入数据

这里是MainActivity代码:

public class MainActivity extends Activity { 

EditText name,age,email; 
Button b; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
    StrictMode.setThreadPolicy(policy); 
    setContentView(R.layout.activity_main); 
    name = (EditText) findViewById(R.id.name); 
    age = (EditText) findViewById(R.id.age); 
    email = (EditText) findViewById(R.id.email); 
    b = (Button) findViewById(R.id.done); 

    b.setOnClickListener(new View.OnClickListener() { 
     InputStream is = null; 
     @Override 
     public void onClick(View v) { 
      String username = name.getText().toString(); 
      String userage = age.getText().toString(); 
      String useremail = email.getText().toString(); 
      //setting the nameValuePair 
      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); 
      nameValuePairs.add(new BasicNameValuePair("username",username)); 
      nameValuePairs.add(new BasicNameValuePair("userage",userage)); 
      nameValuePairs.add(new BasicNameValuePair("useremail",useremail)); 
      // 
      try{ 
       HttpClient httpClient = new DefaultHttpClient(); 
       HttpPost httpPost = new HttpPost("http://sql17.000webhost.com/phpMyAdmin/index.php?db=a6923033_hamsau&lang=en-utf-8&token=4abc43994f0264c44701d85da5b524ee&phpMyAdmin=qsZJnJbsiQaPRx-aDIDtwuxOx5f,new.php"); 
       httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
       HttpResponse httpResponse = httpClient.execute(httpPost); 
       HttpEntity entity = httpResponse.getEntity(); 
       is = entity.getContent(); 

      } 
      catch (UnsupportedEncodingException e) { 
       Log.i("Hammas","UnsupportedEncodingException "+e); 
      } catch (ClientProtocolException e) { 
       Log.i("Hammas", "ClientProtocolException " + e); 
      } catch (IOException e) { 
       Log.i("Hammas", "IOException " + e); 

      } 
      Toast.makeText(getApplicationContext(),"Data is entered",Toast.LENGTH_SHORT).show(); 

     } 
    }); 

} 



} 

这里是phpscript

enter code here 
<?php 
$mysql_host = "mysql17.000webhost.com"; 
$mysql_database = "a6923033_hamsau"; 
$mysql_user = "a6923033_hamsau"; 
$mysql_password = "123master95"; 

$name=$_POST['name']; 
$age=$_POST['age']; 
$email=$_POST['email']; 

mysql_query("insert into users(name,age,email)values('{$name}','{$age}',  {$email}')"); 

?> 

我认为有错误的HTTP链接或phpscript,因为这些都只是一些我没了解清楚

+1

我当然希望那些不是你的实际DB凭证。如果他们是,你最好现在就去改变他们。 –

+0

你能否更清楚你的答案? – Usman

+0

你基本上只是把整个世界的钥匙给了你的数据库。你可能有一天醒来,发现一切已被删除 – Osuwariboy

回答

-1

你的代码是绝对正确和有效的,但有一点是你创建了具有相同名称和相同列名的表。

+0

请提出代码是如何完全正确和正常工作的,以及用相同名称创建的表具有相同的列名? – Shehary

+0

好吧,我也有行'mysql_query(“插入到用户(姓名,年龄,电子邮件)值('{$ name}','{$ age}',{$ email}')”)中的错误; '...但表名是'用户'? – Usman

+0

@Usman,尝试不带'{name','$ age',$ email''的查询 – Shehary