I’m trying to build a mobile application with PhoneGap and jQuery Mobile . In my app I have a page where is a link to PHP file which updates MYSQL and heads to next page. But with PhoneGap I need to have all the PHP files on external server so I can’t my current solution on this application.
This is the PHP that I use to update MYSQL
<?php
$var = @$_GET['id'] ;
$con = mysql_connect("localhost","username","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
mysql_query("UPDATE table SET condition=true
WHERE ID= \"$var\" ");
header('Location: http://1.2.3.4/test');
mysql_close($con);
?>
So how can I run this PHP when user clicks a button? With jQuery/AJAX i suppose?
Lets say the above PHP code is in file, update.php. Then you can use the following code –
Just pass a valid id in the UpdateRecord function. Put your PHP code in update.php file. Just to be on a safer side, in your PHP code replace
$var = @$_GET['id'] ;with$var = @$_POST['id'] ;and check if this works for you