0

I am beginner in mysql database. I am trying to create an online database application in android. This is a user registration application. I have tested this app with emulator and it succesfully inserting the entered data into database. At the same time tested this app with a real android device and can't insert the data into the database. Is it possoble to do? How can I do this with the same offline server. I am using wampserver version 2.5. My php code given below

<?php
$servername = "localhost";
$username = "micro";
$password = "micro";
$dbname = "insert_user";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}


     $name=$_POST['user'];
                 $pass=$_POST['pass'];
                 $email=$_POST['email'];

$flag['code']=0;



$sql = "INSERT INTO user(name,pass,email)VALUES('$name','$pass','$email')";

if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} 
else 
{
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);

?>

Logcat

2
  • "At the same time tested this app with a real android device and can't insert the data into the database" and what does your logcat says? Commented Mar 16, 2015 at 7:15
  • you got error in your json doctype..wrong URL? double check your URL, make sure it can be accesed. turn off your firewall or something Commented Mar 16, 2015 at 7:30

2 Answers 2

1

you need a REST api
try this tutorial, maybe help
http://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-12-2/

Sign up to request clarification or add additional context in comments.

Comments

0

You have to connect your real device with USB cable. If you had connected with USB try to run your IP in a browser of the phone as well as in PC If it opens the wamp server then run the application. If not then click on wamp server's green icon below the screen go to apache and then open httpd.conf file and find(Deny for all) change it to allow for all.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.