Widget HTML Atas

Insert Into Mysql Using PHP Array Post

Form.html

<html>
    <head><title>Tambah Blog</title></head>
<body>
<form action="insert.php" method="POST">
<table >
    <tr><td>Judul</td><td><input type="text" name="title" /></td></tr>
<tr><td>Text</td><td><input type="text" name="text" /></td></tr>
<tr><td></td><td><input type="submit" value="Save" /></td></tr>
</form>
</body>
</html>

Important !!! name of filed in database must same as form field name


insert.php


<?php
foreach ($_POST as $field=>$value) {
$fields[] = '`' . $field . '`';
                $values[] = "'" . mysql_real_escape_string($value) . "'";
                   
                }
                $field_list = join(',', $fields);
                $value_list = join(', ', $values);
                $sql = "INSERT INTO `" . $table . "` (" . $field_list . ") VALUES (" . $value_list . ")";
                mysql_query($sql);
                echo mysql_error();

Search Results Computer Programing, technological, Data Appears, RiskTool, games, memory, MIPS Computer Programing, technological, Data Appears, RiskTool, games, memory, MIPS