Monday, April 8, 2013

[android help] Error while Connecting to Local Server Xampp using Android


I am writing an App in which i am trying to store data into local server in Xampp using Android, but the problem is whenever i do click on save button, cannot save data to local server xampp, i am getting my own defined error message: Error while Registering User



String strError = "Error while Registering User!";


I am using below line to connect to local server Xampp:



String url = "http://127.0.0.1/saveADDData.php";

String url = "http://10.0.2.2/saveADDData.php";


Note: I believe that i am getting problem in above paths.... please let me know what path i need to use to get run my app successuflly...


I guess i am doing mistake while setting path like above twos...


Location of my PHP file is:



E:\xampp\htdocs


Tell me where i am doing silly mistake, what are the changes i need to do to get it work for me.....


FYI : I have successfully created database along with member Table and also able to store records via SQL Query, just getting problem while trying to use Android for this....


First of all i have created a database along with table



Database Name: registration_login
Table Name: member


Secondly, i have written php class code:




$objConnect = mysql_connect("localhost","root","");
$objDB = mysql_select_db("registration_login");

$_POST["sUsername"] = "a";
$_POST["sPassword"] = "b";
$_POST["sName"] = "c";
$_POST["sEmail"] = "d";
$_POST["sTel"] = "e";

$strUsername = $_POST["sUsername"];
$strPassword = $_POST["sPassword"];
$strName = $_POST["sName"];
$strEmail = $_POST["sEmail"];
$strTel = $_POST["sTel"];

$strSQL = "SELECT * FROM member WHERE Username = '".$strUsername."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
$arr['StatusID'] = "0";
$arr['Error'] = "Username Exists!";
echo json_encode($arr);
exit();
}

/*** Check Email Exists ***/
$strSQL = "SELECT * FROM member WHERE Email = '".$strEmail."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
$arr['StatusID'] = "0";
$arr['Error'] = "Email Exists!";
echo json_encode($arr);
exit();
}

$strSQL = "INSERT INTO member (Username,Password,Name,Email,Tel)
VALUES (
'".$strUsername."',
'".$strPassword."',
'".$strName."',
'".$strEmail."',
'".$strTel."'
)
";

$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
$arr['StatusID'] = "0";
$arr['Error'] = "Cannot save data!";
}
else
{
$arr['StatusID'] = "1";
$arr['Error'] = "";
}

mysql_close($objConnect);
echo json_encode($arr);
?>


.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...