Пока кодирование в моем подключении Eclipse к моей базе данных в PHPMyAdmin У меня есть внутренняя ошибка сервера. Я следую за инструкциями по созданию этого php-соединения. Просто интересно, есть ли какая-нибудь ошибка в моем php
файле, который вызывает эту ошибку? Я совершенно не знаком с PHP.Php Проверка имени пользователя и электронной почты (ошибка внутреннего сервера)
$hostname_localhost = "localhost";
$database_localhost = "Username";
$username_localhost = "Root";
$password_localhost = "Root";
$localhost = mysql_connect($hostname_localhost, $username_localhost, $password_localhost) or trigger_error(mysql_error(), E_USER_ERROR);
mysql_select_db($database_localhost, $localhost);
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$result = "select * from tbl_user where username = '$username'";
mysql_query($result);
if (!$result) {
die('Query fail to excute for some reason');
}
if (mysql_num_rows($result) > 0) {
echo "Username Exist";
}
$result1 = "select * from tbl_user where user_email = '$email'";
mysql_query($result1);
if (!$result1) {
die('Query fail to excute for some reason');
}
if (mysql_num_rows($result1) > 0) {
echo "Email Exist";
}
$query_search = INSERT INTO `tbl_user`(`id`, `username`, `password`, `user_email`) VALUES('', '$username', '$password', 'email');
$query_exec = mysql_query($query_search) or die(mysql_error());
echo "User Added";
Для моего андроида код:
void registerUser(){
try{
httpclient=new DefaultHttpClient();
httppost= new HttpPost("http://yoururl.com/register.php"); // make sure the url is correct.
//add your data
nameValuePairs = new ArrayList<NameValuePair>(3);
// Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar,
nameValuePairs.add(new BasicNameValuePair("username", usernameEditText.getText().toString()));// $Edittext_value = $_POST['Edittext_value'];
nameValuePairs.add(new BasicNameValuePair("password", passwordEditText.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("email", emailaddressEditText.getText().toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//Execute HTTP Post Request
response=httpclient.execute(httppost);
// edited by James from coderzheaven.. from here....
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
System.out.println("Response : " + response);
runOnUiThread(new Runnable() {
public void run() {
//tv.setText("Response from PHP : " + response);
dialog.dismiss();
}
});
if(response.equalsIgnoreCase("User Added")){
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(RegisterActivity.this,"注册成功", Toast.LENGTH_SHORT).show();
}
});
SharedPreferences settings = getSharedPreferences(STORED_USER, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("Username", usernameEditText.getText().toString());
editor.commit();
//Jump to next activity while intenting username over
Intent intent = new Intent(RegisterActivity.this, LeftAndRightActivity.class);
intent.putExtra(USER_NAME, usernameEditText.getText().toString());
startActivity(intent);
}else if(response.equalsIgnoreCase("Email Exist")){
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(RegisterActivity.this,"这邮箱已有账号", Toast.LENGTH_SHORT).show();
}
});
}else if(response.equalsIgnoreCase("Username Exist")){
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(RegisterActivity.this,"这用户名已有人使用", Toast.LENGTH_SHORT).show();
}
});
}else{
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(RegisterActivity.this,response, Toast.LENGTH_SHORT).show();
}
});
}
}catch(Exception e){
dialog.dismiss();
System.out.println("Exception : " + e.getMessage());
}
Error Log:
12-17 19:09:30.519: W/SingleClientConnManager(9526): Invalid use of SingleClientConnManager: connection still allocated.
12-17 19:09:30.519: W/SingleClientConnManager(9526): Make sure to release the connection before allocating another one.
Можете ли вы предоставить сообщение об ошибке и соответствующий раздел кода. –
Это значит, что код .PHP верен? – user1758158
Да, нам нужно сообщение об ошибке и бит кода, вызывающий ошибку. –