Error form php to real server

0

I have a problem, and that is when trying to make a form to add values, the form stays on the same page .php and ignores any if or else ..

Messages.php - >

form:

<form action="mensajes.php">
    <input type="text" name="alias" class="input">
    <input type="text" name="publio" class="input">
    <input type="text" name="publit" class="input">
    <input type="text" name="personas" class="input">
    <input type="text" name="lugar" class="input">
    <input type="text" name="remitente" class="input">
    <input type="text" name="destinatario" class="input">
    <input type="date" name="data">
    <input type="submit" value="dale" name="submit">
</form>

<?php 
    include('conexionbd.php');
    session_start();    
        if(isset($_POST['submit'])){
            $alias = $_POST['alias'];
            $publio = $_POST['publio'];
            $publit = $_POST['publit'];
            $personas = $_POST['personas'];
            $lugar = $_POST['lugar'];
            $remitente = $_POST['remitente'];
            $destinatario = $_POST['destinatario'];
            $data = $_POST['data'];
                $sql = "INSERT INTO publicaciones (id,alias,publi_original,publi_traducida,personas_implicadas,lugar,dataa,remitente,destinatario) VALUES ('dummy','$alias','$publio','$publit','$personas','$lugar','$data','$remitente','$destinatario')";                
                $resultado = $conexion->query($sql);
                $filas = $resultado->num_rows;
                if($filas>0){
                        echo "bien";
                    }else{
                        echo "Error al agregar mens";
                    }
        }
    ?>
    
asked by Juliian68 22.11.2017 в 15:17
source

1 answer

1

Simply missing the attribute method to your <form> .

The method attribute can receive two method="get|post" values. When you forget to place this attribute on the <form> tag, the data will be sent by default by get method and as in PHP you are receiving it as if it were by method post then that conflict that you have had is generated.

<form action="mensajes.php" method="post">

On the other hand, the condition will never be fulfilled because you are doing a INSERT and not a SELECT , when you make a INSERT the system returns you simply true if it was successful or false otherwise, then the validation must be done as follows:

if($resultado){
   echo "bien";
}else{
   echo "Error al agregar mens";
}
    
answered by 22.11.2017 / 15:54
source