<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>
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();
Tidak ada komentar:
Posting Komentar