Ich möchte den Wert einer Zelle in PostgreSQL aus einem Leaflet-Popup aktualisieren. Was ich versuche zu tun ist eine JavaScript-Funktion, wenn die Schaltfläche zum Senden innerhalb eines Formulars gedrückt wird, und danach den Wert, der in das Formular eingegeben wurde, über ein PHP-Skript innerhalb der Javascript-Funktion, PostgreSQL Datenbank.Aktualisieren eines Werts in PostgreSQL aus dem Leaflet-Popup
So sieht meine Popup-Funktion mit ihrer Form aus.
function onEachFeature(feature, layer) {
insertsearch = feature.properties.gid
popUpText = "<b>Name</b>: " + feature.properties.businessna +
"<br> <b>Address: </b>" + feature.properties.addresslin + ", " + feature.properties.addressl_1 +
"<br><b>Food hygiene rating</b> <span id=skala>(1-5)</span> : " + feature.properties.ratingvalu +
"<form id='formoid' action='javascript:insertdata();'><br>Rating (between 1 and 5): <input type='number' name='quantity' min='1' max='5'><input type='submit'></form>"
feature.properties.gid;
feature.properties.popupContent = popUpText;
if (feature.properties && feature.properties.popupContent) {
layer.bindPopup(feature.properties.popupContent);
}
};
Hier ist das PHP-Skript i verwenden möchten: (insert.php)
<?php
header("Access-Control-Allow-Origin: *");
$conn_str = "host=localhost dbname=geoweb
user=user password=user";
$dbconn = pg_connect($conn_str)
or die('Could not connect: ' . pg_last_error());
//innumber is supposed to be the rating value given by the user in the HTML form
$innumber=;
//idnumber is supposed to be the GID of the point that is being rated
//GID is this variable in the HTML function (insertsearch = feature.properties.gid)
$idnumber=;
//norate is the NUMBER OF TIMES the place has been rated
$norate= pg_query($dbconn, "SELECT rate FROM rating WHERE gid=$idnumber");
//findnumber is getting THE RATING value that the place already has
$findnumber= pg_query($dbconn, "SELECT rateav FROM rating WHERE gid=$idnumber");
//newvalue adds the existing rating value to the users new rating
$newvalue= $innumber + $findnumber;
//adds on 1 (one) to the norate to update how many times the place has been rated
$newcount= $norate+1;
//the query is updating the new rating value of the place.
//It replaces the old rating value with the a new value
$query="UPDATE rating SET rateav=$newvalue, rate=$newcount WHERE gid=$idnumber";
$result = pg_query($dbconn, $query);
pg_freeresult($result);
pg_close($dbconn);
?>
jetzt Mein Problem heraus ist herauszufinden, wie die JavaScript-Funktion zu schreiben. Wie ich es verstehe, sollte ich eine jquery $ post-Methode verwenden, um die Daten über das Skript insert.php zu senden. Wie soll ich aber Parameter an die JS-Funktion im HTML-Formular senden (action = ...)? Wenn ja, wie mache ich das? Ich versuche, zwei Werte über das PHP-Skript zu senden, das ist die InsertSearch Variable in der Popup-Funktion (um den richtigen Eintrag in der Tabelle zu erhalten), und die vom Benutzer im Formular angegebene Bewertungszahl.
Danke für Ihre Hilfe!