Send Textbox text to PHP

Dear Experts

I have following blocks

The codes work fine, data is saved into mysql table.

But I want to get the value of Textbox named date2 into PHP file like

<?php

&my_date='';
&my_date="?" // value from MIT APP Inventor Textbox named date2
?>

How is it possible to send the value of this textbox to PHP file

component_set_get

I am already using php file like

Actually I want to use the value of this textbox as a variable in php.

I have tried in this way

<?php

$my_date='';
$my_date=mysqli_real_escape_string($dbc, $_GET["date"]);
echo $my_date;

?>

but it is displaying an empty string.

Thanks in advance

$boton = $_GET['boton'];

/////////////////////////////// INSERTAR ////////////////////////////////////
if ($boton == "btnEnviar"){
$Nombre = $_GET['Nombre'];
$Edad = $_GET['Edad'];
$Ciudad = $_GET['Ciudad'];
$query="insert into personas (Nombre, Edad, Ciudad) values ('$Nombre','$Edad','$Ciudad')";
$result = mysql_query($query);
}

http://kio4.com/appinventor/340B_appinventor_mysql.htm

Sir Juan_Antonio

While seeing you example I modified my blocks like this

and my php file is like this

<?php
$servername = "localhost";
$username = "id20649282_aslam";
$password = "zahid@123456";
$database = "id20649282_cng";

$dbc = mysqli_connect($servername, $username, $password, $database);

if (!$dbc) {
    die("DATABASE CONNECTION FAILED:" . mysqli_error($dbc));
    exit();
}

$datex = $_GET["mydate"];

$query2 = "select * from sales where ddate='$datex' ";

$result = mysqli_query($dbc, $query2);

if ($result) {
    $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"]);
    $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: Could2 not able to execute" .
            $query .
            " " .
            mysqli_error($dbc);
    }
}

mysqli_close($dbc);
?>

When I run codes then this error message appears

I think php is getting value with variable
Please help me to get actual value (2023-12-12) after where clause like
Where ddate='2023-12-12'

Please help

Change
mydate=

&mydate=

1 Like

Sir where should I change?
In blocks or in php
Regards

In principle in Blocks, then you have to check if the php works.

1 Like

Sir this time no date truncated message appeared but ..

Query result says: Record updated...

My query is


<?php

$dbc = mysqli_connect($servername, $username, $password, $database);

if (!$dbc) {
    die("DATABASE CONNECTION FAILED:" . mysqli_error($dbc));
    exit();
}

$datex = $_GET["mydate"];
$query2 = "select * from sales where ddate='$datex'";
$result=mysqli_query($dbc, $query2);

    if ($result) {
        $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"]);
        $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 {
       //$date = 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"]);
        $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);
?>

It means this part of query

$datex = $_GET["mydate"];
$query2 = "select * from sales where ddate='$datex'";
$result=mysqli_query($dbc, $query2);

    if ($result) {

is not working still.

Purpose of above query:
If use enters any date then query checks if date already exists
if yes then all records will be updated
if given date does not exists in table then a new record will be entered.

Please help me in this final stage.

Regards

Do you know how to adapt this code?

http://kio4.com/appinventor/340C_appinventor_mysqli.htm

1 Like

Yes sir I have seen all codes deeply. I refer to this portition

If I follow above codes and enter a date like '2023-12-12' more than 1 time then there will be no restriction or validation to avoid this record to be entered into table.

In my case I want to insert any date only 1 time. there will be no duplicated dates.

So before inserting record, I want to assure that given date is already exist or not exists.

Regards

Try this

$date = $_GET['date'];
$p_ltr = $_GET['p_ltr'];
$p_rat = $_GET['p_rat'];
$p_amt = $_GET['p_amt'];
$datex = $_GET['mydate'];

$query2 = "select * from sales where ddate='$datex'";
$result=mysqli_query($dbc, $query2);

    if ($result) {
        $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) VALUE ('$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);
?>
1 Like

image

question mark (?) immediately followed by ampersand (&) ?

1 Like

Thanks sir, problem solved. You are really great. I rate you.
Regards

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.