how can I save data from an html form to a mysql db

0

Hello, I need to know how to save data to my mysql database using php:

- this is my connection     

$con = mysqli_connect($host,$user,$pw,$db) or die ("no conecta al servidor local");

mysqli_select_db($con,$db) or die ("no conecta a la base de datos");

if ($con == TRUE) {
    echo "Conexion al host";

}

else{
    echo "no conecta";
}

? >

and this is my form *

<form method="post" action="php/registro.php">
            <label>Nombre</label><br>
            <input type="text" name="nombre" placeholder="Nombre" required=""><br>
            <label>Apellido</label><br>
            <input type="text" name="apellido" placeholder="Apellido" required=""><br>
            <label>Correo Electronico</label><br>
            <input type="email" name="correo" placeholder="[email protected]" required=""><br>
            <label>Contraseña</label><br>

            +56 <input type="varchar" name="telefono" placeholder="" required=""><br>
            <label>Sexo</label><br>

            <input type="radio" name="sexo" value="hombre">Hombre<br>
            <input type="radio" name="sexo" value="mujer">Mujer<br>
            <input type="radio" name="sexo" value="otro">Otro/a<br>
            <input type="submit" name="enviar" value="Enviar">
            <input type="reset" name="" value="Borrar">
        </form>
    
asked by Mr.Manutri 23.03.2018 в 19:03
source

1 answer

0

What you should do is the following

  • In that file you need to receive your variables by POST $_POST['nombre']
  • Then you should include the connection to your database.
  • Perform the INSERT to the table in your DB

    include 'conexion.php'; //Recibes las variables por POST $nombre=$_POST['nombre']; $apellido=$_POST['apellido']; //Haces lo demas con el resto de los campos de tu formulario //Realizas el Insert a tu bd $sql="INSERT INTO tabla (nombre,apellido) VALUES ('$nombre','$apellido')"; //Ejecutas tu consulta y listo

  • answered by 23.03.2018 / 19:22
    source