This example is based on this topic:
https://community-appinventor-mit-edu.ezproxy.canberra.edu.au/t/a-strange-behaviour-of-response/82885
BaseDatos_MySql.aia (5.5 KB)
This MySQL
cng_insert2.php
<?php
date_default_timezone_set("Europe/Madrid");
$servername = "localhost";
$username = "id20681340_fake";
$password = "Contraseña_fake";
$database = "id20681340_gas";
$dbc = mysqli_connect($servername, $username, $password, $database);
if (!$dbc) {
die("DATABASE CONNECTION FAILED:" . mysqli_error($dbc));
exit();
}
$boton = mysqli_real_escape_string($dbc, $_GET["boton"]);
if ($boton == "btnSend"){
$datex = mysqli_real_escape_string($dbc, $_GET["date"]);
$p_ltr = mysqli_real_escape_string($dbc, $_GET["p_ltr"]);
$p_rat = mysqli_real_escape_string($dbc, $_GET["p_rat"]);
$p_amt = mysqli_real_escape_string($dbc, $_GET["p_amt"]);
$query2 = "select * from sales where ddate='$datex'";
$result=mysqli_query($dbc, $query2);
$rows_count = mysqli_num_rows($result);
if ($rows_count > 0) {
$query = "update sales set p_ltr='$p_ltr',p_rat='$p_rat',p_amt='$p_amt' where ddate='$datex'";
if (mysqli_query($dbc, $query)) {
echo "Records updated successfully.";
exit();
} else {
echo "ERROR: Could not able to execute" .$query." ".mysqli_error($dbc);
}
} else {
$query = "INSERT INTO sales(ddate,p_ltr,p_rat,p_amt)
VALUES ('$datex','$p_ltr','$p_rat','$p_amt')";
if (mysqli_query($dbc, $query)) {
echo "Records added successfully.";
} else {
echo "ERROR: Could not able to execute" .$query." ".mysqli_error($dbc);
}
}
mysqli_close($dbc);
};
if ($boton == "btnGet"){
$hacer = mysqli_query ($dbc, "SELECT * FROM sales");
$resultado = mysqli_query($GLOBALS['dbc'], "SHOW COLUMNS FROM sales");
$numerodefilas = mysqli_num_rows($resultado);
if ($numerodefilas > 0) {
$en_csv='';
while ($rowr = mysqli_fetch_row($hacer)) {
for ($j=0;$j<$numerodefilas;$j++) {
$en_csv .= $rowr[$j].",";
}
$en_csv = substr($en_csv, 0, -1);
$en_csv .= "\n";
}
}
$en_csv = substr($en_csv, 0, -1);
print $en_csv;
mysqli_close($dbc);
}
?>
MySql from
http://kio4.com/appinventor/340C_appinventor_mysqli.htm