My code dont get the information in mysql database using post app inventor help

there is mi php code and there is my blocks. i dont know why i get this message undefined array key "boton" in /storage/ssd3/292/21963292/....

// 1.- IDENTIFICACION nombre de la base, del usuario, clave y servidor
// 2.- CONEXION A LA BASE DE DATOS
include_once "pruebaconexionwebhost.php"; // Incluir el archivo con la conexión a la base de datos

$boton = $_POST['boton'];

/////////////////////////////// INSERTAR - INSERT ////////////////////////////////////
if ($boton == "btnInsertar"){
$nombre = $_POST['nombre'];
$email = $_POST['email'];
$telefono = $_POST['telefono'];
$query="INSERT INTO clientes (nombre, email, telefono) VALUES ('$nombre','$email','$telefono')";
$result = mysqli_query($link, $query);
print("Datos agregados a la base.");
mysqli_close($link);
}

i am using am example to send data to mysql hosting and there are my blocks

image

You need to add & before nombre.

Also, please always show your full url.

i get the same error there is the url https://pruebaconmiarchivophp.000webhostapp.com/basededatos/codigomysqli.php and there is my aia

envio(1).aia (2.6 KB)

Please show your full php file

I used these blocks (note the use of double quotes around "btInsertar") and the php file returned:

and the php file returned:

Conexión exitosa a la base de datos!
translated
Successful connection to the database!

there is my full code

the include pruebaconexionwebhost.php is that

<?php // Datos de conexión a la base de datos $servername = "localhost"; // Cambia esto si es necesario $username = "id21963292_nickolae"; $password = "JUEGOS1990()q"; $dbname = "id21963292_testeo"; // Intentar conectar a la base de datos $link = new mysqli($servername, $username, $password, $dbname); // Verificar la conexión if ($link->connect_error) { die("La conexión falló: " . $link->connect_error); } else { echo "Conexión exitosa a la base de datos!"; } // Cerrar la conexión $link->close(); ?>

and the other full code is

<?php // Juan Antonio Villalpando // juana1991@yahoo.com // http://kio4.com // https://kio4.000webhostapp.com/mysqli_post.php // 1.- IDENTIFICACION nombre de la base, del usuario, clave y servidor // 2.- CONEXION A LA BASE DE DATOS include_once "pruebaconexionwebhost.php"; // Incluir el archivo con la conexión a la base de datos $boton = $_POST['boton']; /////////////////////////////// INSERTAR - INSERT //////////////////////////////////// if ($boton == "btnInsertar"){ $nombre = $_POST['nombre']; $email = $_POST['email']; $telefono = $_POST['telefono']; $query="INSERT INTO clientes (nombre, email, telefono) VALUES ('$nombre','$email','$telefono')"; $result = mysqli_query($link, $query); print("Datos agregados a la base."); mysqli_close($link); } /////////////////////////////// BORRAR - DELETE //////////////////////////////////// if ($boton == "btnBorrar"){ $Nombre = $_POST['nombre']; $query="delete from clientes where nombre='$nombre'"; $result = mysqli_query($link, $query); print("Datos borrados."); mysqli_close($link); } ////////////////////////////// ACTUALIZAR - UPDATE /////////////////////////////// if ($boton == "btnActualizar"){ $nombre = $_POST['nombre']; $email = $_POST['email']; $telefono = $_POST['telefono']; $query="update personas set email='$email', telefono='$telefono' WHERE nombre='$nombre'"; $result = mysqli_query($link, $query); print("Datos modificados."); mysqli_close($link); } ///////////////////// BUSCAR POR NOMBRE - SEARCH BY NAME ///////////////////////////// if ($boton == "btnBuscarNombre"){ $nombre=$_POST['nombre']; $hacer = mysqli_query ($link, "SELECT * FROM clientes WHERE nombre='$nombre' "); enviar_respuesta($hacer); } /////////////////////// MOSTRAR TABLA - SHOW TABLE ///////////////////////////////////// if ($boton == "btnVerTabla"){ $hacer = mysqli_query ($link, "SELECT * FROM clientes"); enviar_respuesta($hacer); } /////////////////////// OBTENER ORDENADO - GET SORT ///////////////////////////////////// if ($boton == "btnOrdenar"){ $Columna = $_POST['Columna']; $hacer = mysqli_query ($link, "SELECT * FROM clientes ORDER BY $Columna ASC"); enviar_respuesta($hacer); } ////////////////////////////// RESPUESTA - RESPONSE /////////////////////// // En los casos que hay btnBuscarNombre o btnVerTabla y se debe enviar una respuesta actúa este código. function enviar_respuesta($hacer) { $resultado = mysqli_query($GLOBALS['link'], "SHOW COLUMNS FROM clientes"); $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 .= "\n"; } } print $en_csv; } /////////////////////////////////////////////////////////////////// ?>

Looks like my blocks are getting you this far:

<?php // Datos de conexión a la base de datos $servername = "localhost"; // Cambia esto si es necesario $username = "id21963292_nickolae"; $password = "JUEGOS1990()q"; $dbname = "id21963292_testeo"; // Intentar conectar a la base de datos $link = new mysqli($servername, $username, $password, $dbname); // Verificar la conexión if ($link->connect_error) { die("La conexión falló: " . $link->connect_error); } else {

echo "Conexión exitosa a la base de datos!";

} // Cerrar la conexión $link->close(); ?>

Can you provide the link to the topic where Juan's original php is located?

What are you expecting this code to do with your three items of data ?

(Note: it would help if you provided formatted (pretty print) php)

the three items is for send data and give the result of data in 2 differents applications
here is the link App inventor. App inventor y MySQLi. PHP. GET. POST. Página web. Base de datos

In your file pruebaconexionwebhost.php

don't close the link, otherwise your subsequent commands will not work!

Remove this:
// Cerrar la conexión
$link->close();

i delete the lines that you say me but i get the same error undefined array key "boton" in /storage/ssd3/... what is wrong?

Did you put the double quotes around "btInsertar" ?

yes see

you're missing a "?"

but the post sending data use ? in the url? its not only for get?

Right, sorry I didn't notice that it wasn't a get

i didnt understand where is my error. i am following all the steps but my database mysql in php my admin dont get the post data

empty? you must have a space here.

so i need to change this part of my blocks?

in this link the guide sayme that use this blocks for replace the empty spaces App inventor. App inventor y MySQLi. PHP. GET. POST. Página web. Base de datos

With that "replace" block you want to replace the blanks, by %20. Then you need to have a blank in "segment" (now you have an empty string...which is not the same). Put a space in the "segment" string.

1 Like