I am slightly new to programming, I have had a few friends help me out with getting my Phone Gap app to post local storage to Postgres via PHP. When I had the PHP hosted on a local server, the jQuery was connecting to the PHP page and posting correctly to my Postgres database.
However, as soon as I migrated everything over to AWS, the jquery was unable to connect to (or find?) the PHP page.
My jQuery function is as follows
function submitForm() {
var string = localStorage.getItem("entry");
$.get("http://www.mywebsite.com/get.php", { q: string } ).done( function() { window.location = "#/app/thanks";}).fail( function() { alert('Please check your Internet connection and try again.'); });
return 1;
}
and my PHP
<?php
$query = $_GET['q'];
$array = explode("|", $query);
$species = explode(",", $array[2]);
$array2 = explode(",", $array[3]);
$i = 0;
$db = pg_connect("host=<aws db endpoint> port=5432 dbname=database user=postgres password=<my password>) or die('Could not connect: ' . pg_last_error());
for($i=0;$i<10;$i+=2) {
if($i == 0) {
$fishKept = $array2[1];
$hoursFished = $array2[2];
}
else {
$fishKept = 0;
$hoursFished = 0;
}
$q = "INSERT INTO creel(waterbody_id, species, species_length_id, fish_caught, fish_kept, hours_fished, date) VALUES('".$array[0]."', '".$array[1]."', '".$species[$i]."', '".$species[$i+1]."', '".$fishKept."', '".$hoursFished."', '".$array2[0]."');";
$result = pg_query($db, $q);
}
pg_close($db);
?>
When I try to run the function, it gives me the alert "Please check your internet connection and try again", which tells me the function is failing. Currently the php is in /var/www/html
on my AWS server. Does the PHP need to be in a certain place? I didn't change any of the code, so I do not see why it would work for posting to the local server but not AWS.
I have my Postgres database set up using RDS, and I am able to connect to it with pgAdminIII on my computer, so I do not think it is a security issue.
I believe I have all my login info correct for Postgres, but it doesn't seem to be running the PHP at all.