https://community.appinventor.mit.edu/t/insert-data-to-mysql/82604/11
The idea was to remove the entire block replacing spaces.
Never leave empty inputs in blocks because it may cause errors when compiling or using the app and you won't be able to find the cause. Remember all block inputs must be completed.
Sir this time I have removed Replacement block like this
But
Unfortunately the problem is still exist.
I have to click SUBMIT button TWICE to save data.
Regards
Yes, that wasn't the cause of the error. I just noticed an empty block input that shouldn't be there.
You have not corrected the code that @TIMAI2 told you about in a previous topic.
cng_insert2.php?&date=
cng_insert2.php?date=
Sir it was
https://lettered-manners.000webhostapp.com/cng_insert2.php?&date=
Now I have replaced it with
https://lettered-manners.000webhostapp.com/cng_insert2.php?date
But issue is still alive
May be I am doing wrong anywhere.
Regards
Please show your web2.GotText event block
There is no -1
http response code, so where is -1
coming from ?
[EDIT - the above is incorrect - see below]
use Do it to debug your blocks, see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
see also Live Development, Testing, and Debugging Tools
EDIT: what happens, if you call that url in a browser`?
Taifun
Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.
I tell a lie, there does appear to be an http status code of -1
.
This is usually attributed to network or connectivity problems.
I can think of a workaround, where if you receive -1
then the data is submitted again,
but this is not really the answer, unless your first click just so happens to bring the server alive, then it is possible to send the data on the second click. Other than that, I am out of suggestions.
you forgot to provide a Do it result as suggested earlier so we can check the url
without you using Do it we only can guess...
EDIT: as I can see now you called the url without parameter... this does not help, does it?
obviously you have to send a complete url to the server...
this is an example of a complete url
Taifun
Should the first parameter be "ddate" and NOT "date" ?
according to the php script it should be mydate... LOL...
$datex = $_GET["mydate"];
$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"]);
EDIT: what is the &date variable supposed to do? as far as I can see, it is ignored in the php script...
Taifun
In addition to all the other recommendations, it is wise to break up over-long text blocks into a JOIN of two shorter, fully visible text blocks.
You never know what is hiding in that '...' at the end of the block.
<?php
date_default_timezone_set("Europe/Madrid");
$servername = "localhost";
$username = "id20680000_my_user";
$password = "contraseña";
$database = "id20680000_my_base";
$dbc = mysqli_connect($servername, $username, $password, $database);
if (!$dbc) {
die("DATABASE CONNECTION FAILED:" . mysqli_error($dbc));
exit();
}
$datex = $_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: Could3 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);
?>
Respected Sir,
Here is DO IT result
Here is complete text in DO IT popup box
Do It Result: "https://lettered-manners.000webhostapp.com/cng_sample.php?date=2023-05-01&p_ltr=9.00&p_rat=75.22&p_amt=677.00&mydate=2023-05-01"
You are all experts, so you know better what does it mean but I think there is date format problem. I am using this format
Second result when data saves:
Please help me I have to still click SUBMIT Button twice to save one record.
Regards
date and mydate is the same information?
Do you obtain those dates with the DatePicker?
I'm going to create a new topic about this example.
Yes Sir, date and mydate has same date that comes from DatePicker.
Regards
![](https://community.appinventor.mit.edu/user_avatar/community.appinventor.mit.edu/tariq_mehmood/48/110437_2.png)
has same date that comes from DatePicker.
Try this
This example is based on this topic: https://community.appinventor.mit.edu/t/a-strange-behaviour-of-response/82885 BaseDatos_MySql.aia (5.5 KB) [mysql_fecha3] This MySQL [mysql_fecha1] [mysql_fecha2] 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 CO…