Dear experts
I have following code block
this is connection string
[type or paste code here](https://lettered-manners.000webhostapp.com/cng_insert2.php?&date=)
and my php file is like this
<?php
date_default_timezone_set("Asia/Karachi");
$servername = "localhost";
$username = "id2064282_ahmad";
$password = "123456";
$database = "id2064282_cng";
$dbc = mysqli_connect($servername, $username, $password, $database);
if (!$dbc) {
die("DATABASE CONNECTION FAILED:" . mysqli_error($dbc));
exit();
}
$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"]);
$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);
?>
When I FIRST TIME click SUBMIT button then this error message appears
and when I SECOND TIME click SUBMIT button then this response receives
As a result I have to click SUBMIT button TWICE every time to save a single row in table.
First time response is -1
second time response is 200
I am very much confuse where is problem? in blocks or in PHP file.
Sir I have tested this more than 20 times.
As a general SUBMIT button must work on every click.
Please