I have tried server side PHP code it was working fine, but i cant store any data to mysql table… How to connect mysql. i am using phonegap interface to run ionic app in localhost. I am very new to ionic and phonegap. If know anybody help me on that… Thanks in advance…
it depends where you want to run mysql
Normally:
Your backend is connected to a database… so you can checkout php + mysqli https://secure.php.net/manual/en/book.mysqli.php
If you want to store the data on the device as well --> you can use sqlite-cordova-plugin
http://ngcordova.com/docs/plugins/sqlite/
Thanks for your reply, i want to store my data into mysql instead of mobile local storage, i am using Linux hosting,
my js code
$http.post(link, {username : $scope.data.username,email:$scope.data.email,password:$scope.data.password}).then(function (res){
alert(res.data);
$scope.res_div=false;
$scope.loading = false;
$scope.response = res.data;
});
php code:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);
if (isset($_SERVER['HTTP_ORIGIN']))
{
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');
}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS')
{
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers:{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
$postdata = file_get_contents("php://input");
if (isset($postdata))
{
$request = json_decode($postdata);
$username = $request->username;
$email = $request->email;
$password = $request->password;
$enc_pwd = sha1($password);
if ($username != "")
{
$result=mysql_query("insert into register values ('','$username','$email','$enc_pwd','$cur_date')");
if($result)
{
echo "Successfully registered";
}
}
else
{
echo "Empty username parameter!";
}
}
else
{
echo "Not called properly with username parameter!";
}
?>
Note: when i run the app from my mobile i am getting full php code as a response…
Please, could you beautify and format you code correctly ?
yes, i have beautified and formatted my code…
I want your email if possible