Create a form in which when you submit to submit, the written text is uploaded to a server

0

I have a form

<form action="" method="post" class="basic-grey">
<h1>Bible Form 
    <span>Please fill all the texts in the fields.</span>
</h1>
<label>
    <span>Your Nickname* :</span>
    <input id="name" type="text" name="name" placeholder="insert your nickname" />
</label>

<label>
    <span>Your Email* :</span>
    <input id="email" type="email" name="email" placeholder="Valid Email Address" />
</label>

<label>
    <span>Message* :</span>
    <textarea id="message" name="message" placeholder="Insert the text u desire"></textarea>
</label> 
 <label>
    <span>Code* :</span>
    <input id="code" type="email" name="email" placeholder="The Code That we sent to your email" />
</label>    
 <label>
    <span>&nbsp;</span> 
    <input type="button" class="button" value="Send" /> 
</label>    

My goal is that in that form, when filling in all the data. (We can skip the last box of the code, that stops later). And when giving the user to submit, upload what is in MESSAGE to a file located on the server (I guess that goes by php and mysql). And to be able, that if 10 users upload 10 texts, that all these are in a single file consecutively (one below the other).

    
asked by romanturbo 12.12.2016 в 19:49
source

4 answers

1

Here is a small example of what you are asking:

HTML FORM:

<form method="post" action="insertar_colores.php" enctype="multipart/form-data">
    <div class="form-group">
        <div class="row">
            <div class="col-md-4">
                <label for="nombre">Nombre:</label><br>
                    <input name="nombre" type="text" class="form-control" id="nombre" placeholder="EJ: Un nombre"/>
            </div>
        </div><br>
        <!--FIN CAMPOS-->
    </div>
    <button type="submit" class="btn btn-primary">Enviar informacion</button>
</form>

ENTER PHP DATA

if(addslashes($_POST['nombre']) == '' or addslashes($_POST['nombre']) == NULL){
    echo "Te olvidaste de poner el nombre";
    exit;
}
// APARTIR DE AQUI ES TODO CORRECTO Y EMPEZAMOS A GUARDAR COSAS
        else{echo $razon."<br>";
        #Consulta a la BD para insertar los datos
        $links = conectar_db();
        $consultar_mensaje = "INSERT INTO tabla VALUES ('NULL', '".addslashes($_POST['nombre'])."')";
        $result_mensaje = mysqli_query($links, $consultar_mensaje);
        #FIN conecxion a la BD

//COMPROBACION DE QUE TODO ES CORRECTO EN LA BASE DE DADOS
                    if (isset($result_mensaje) == FALSE) {
                        echo"Error: ".$consultar_mensaje."<br>ERROR TIPO 2".$links->error;
                        echo "<br>No se a enviado el mensaje";
                    } else {
                        echo"Se a guardado en nuestra base de datos<br>";
                        echo"<br><b>Todo correcto</b><br>";
                        }
                    }
}else{echo"Los datos ya han sido introducidos en la base de datos!";}

I want to think that you already know how to add a database and manage it so that you fill in the fields that you have to have created (I only made a field called "name" as an example)

    
answered by 15.12.2016 в 02:26
0

You will have to deal with the sending of html forms data first. Your form does not have an action. There I would put a executeform.php for example. I also do not see that you close the html tag of the% </form> .

The action of the form is destiny. In that destination there will have to be a php file in which you will collect the data you receive from the form (in this case by POST method) and handle them at your whim ... either by saving them in a bbdd mysql, or as you also indicated adding to a file the data of a certain field of the form or whatever ...

I recommend you read this

    
answered by 12.12.2016 в 20:02
0

Really what you will have to do first is to put the PHP file where you will process the data in the action of the form.

<form action="guardoDatos.php" method="post" class="basic-grey">

In this example I will take as a reference guardoDatos.php and the explanation that follows will have reference only with this file.

Subsequently, and since you are sending the data using post (method="post"), you must recover the data, in this case, message, using the global variable $_POST in which you will have stored each one of the fields ( inputs ) that have an attribute name (after submitting in the form).

Therefore, to recover the value of your message, which has the attribute name="message" , you could recover it using $_POST["message"] .

Finally, you will have to make the connection to the database and the insertion of your message to have it stored on your server.

    
answered by 12.12.2016 в 20:08
0

Friend so I understood what you need is to use the fwrite php feature.

The only thing you have to do is that this form sends the parameters to a php file that has a structure, something like this.

if(isset($_POST['message'])){
$data = $_POST['message'];
$carpeta = fopen("archivoUnico.txt", "a+");
fwrite($carpeta, "Mensaje: ".$data."\n");
fclose($carpeta);

}

the "\ n" for the line break. And I recommend adding to that file the username to know which user sent the message.

    
answered by 12.12.2016 в 20:56