Reputation: 95
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);
?>
Upvotes: 0
Views: 4450
Reputation:
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.
Upvotes: 0
Reputation: 1268
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/
Upvotes: 1