Notice: Undefined index: PHP

0

I am learning PHP on my own and I came across this error ...

  

(Notice: Undefined index: name in C: \ xampp \ htdocs \ pdo \ save.php on   line 3

     

Notice: Undefined index: last name in C: \ xampp \ htdocs \ pdo \ save.php   on line 4

Unexpected failure, the information was not saved)

please help, try to solve it with this ...

$nombre = (isset($_POST['nombre']);
$apellido = (isset($_POST['apellido']);

but I still have problems to later visualize the data of the table that I generated to show this data.

<?php
include 'conexion.php';
$nombre = $_POST['nombre'];
$apellido = $_POST['apellido'];


$ins = $con->prepare("INSERT INTO personas VALUES (DEFAULT, :nombre, :ape) ");
$ins->bindparam(':nombre',$nombre);
$ins->bindparam(':ape',$apellido);

if($ins->execute()){
    echo "Guardado con exito";
}else{
    echo" Fallo inesperado, no se guardo la información";
}

?>
    
asked by Erick91 03.01.2019 в 13:33
source

1 answer

-1

<?php

    include 'conexion.php';
    $nombre = $_POST['nombre'];
    $apellido = $_POST['apellido'];

    $qry = "INSERT INTO personas VALUES ('$nombre', '$apellido')";
    $res = mysqli_query($con, $qry)
    if($res){
       echo "Inserción realizada con éxito";
    } else{
       echo "Ha habido un error al insertar el registro"
    }

?>

I would do it this way, we can say that when I use "mysqli_query" the first parameter ($ con) is the variable of the connection, which I guess you'll have it in 'conexion.php'.

    
answered by 03.01.2019 в 14:32