Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Adicionar dados do formulário html a um banco de dados sql usando PHP


Espero que isso ajude

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

insert.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;
?>