sql >> Base de Datos >  >> RDS >> Mysql

Agregue datos del formulario html a una base de datos sql usando PHP

Espero que esto ayude

Formulario.html

<form action="insert.php" method="post">
    <input type="text" name="data">
    <input type="submit">
</form>    

insertar.php

<?php
    //checking if data has been entered
    if( isset( $_POST['data'] ) && !empty( $_POST['data'] ) )
    {
        $data = $_POST['data'];
    } else {
        header( 'location: form.html' );
        exit();
    }

    //setting up mysql details
    $sql_server = 'localhost';
    $sql_user = 'user';
    $sql_pwd = 'password';
    $sql_db = 'database';

    //connecting to sql database
    $myslqi = new mysqli( $sql_server, $sql_user, $sql_pwd, $sql_db ) or die( $mysqli->error );

    //inserting details into table
    $insert = $mysqli->query( "INSERT INTO table ( `data` ) VALUE ( '$data' )" );

    //closing mysqli connection
    $mysqli->close;
?>