Forum Moderators: coopster
if ($_POST['submit']) {
mysql_pconnect('localhost', 'root', '');
mysql_select_db('test');
$result = mysql_query("SELECT * FROM customer");
$col = mysql_num_fields($result);
for ($j=0;$j<$col;$j++) {
$info = array(mysql_field_name($result,$j));
mysql_query("INSERT INTO customer (".$info['0'].") VALUES ('".$_POST[$j]."')");
}
echo "<meta http-equiv=REFRESH content=0;url=http://".$_SERVER['HTTP_HOST'].">";
} else {
echo "<form method=post action=".$PHP_SELF.">";
mysql_pconnect('localhost', 'root', '');
mysql_select_db('test');
$result = mysql_query("SELECT * FROM customer");
$col = mysql_num_fields($result);
for ($j=0;$j<$col;$j++) {
echo mysql_field_name($result,$j) .": <input type=text name=".$j."><br>";
}
echo "<input type='Submit' name='submit' value='Enter'></form>";
}
<?php
mysql_pconnect('localhost', 'root', '');
mysql_select_db('test');
if ($_POST['submit']) {
$result = mysql_query("SELECT * FROM customer");
$col = mysql_num_fields($result);
for ($j=0;$j<$col;$j++) {
$info = array(mysql_field_name($result,$j));
mysql_query("INSERT INTO customer (".$info['0'].") VALUES ('".$_POST[$j]."')");
}
echo "<meta http-equiv=REFRESH content=0;url=http://".$_SERVER['HTTP_HOST'].">";
} else {
echo "<form method=post action=".$PHP_SELF.">";
$result = mysql_query("SELECT * FROM customer");
$col = mysql_num_fields($result);
for ($j=0;$j<$col;$j++) {
echo mysql_field_name($result,$j) .": <input type=text name=".$j."><br>";
}
echo "<input type='Submit' name='submit' value='Enter'></form>";
}
?>
Tell us more about it.
Habtom
if ($_POST['submit']) {
mysql_pconnect('localhost', 'root', '');
mysql_select_db('test');
$result = mysql_query("SELECT * FROM customer");
mysql_query("INSERT INTO customer (name,tel) VALUES ('$name','$tel')");
echo "<meta http-equiv=REFRESH content=0;url=http://".$_SERVER['HTTP_HOST'].">";
} else {
echo "<form method=post action=".$PHP_SELF.">Name: <input type=text name=name><br>Tel: <input type=text name=tel><br><input type='Submit' name='submit' value='Enter'></form>";
}
... but I wish to put fields and values name from TABLE(cols name)
This:
for ($j=0;$j<$col;$j++) {
echo mysql_field_name($result,$j) .": <input type=text name=".$j."><br>";
}
can be simply written as:
?>
<input type="text" name="test[]" />
<input type="text" name="test[]" />
<input type="text" name="test[]" />
....
as many as you want.
if you print_r($_REQUEST['test']); you will get the whole values from those boxes in the following format:
Array
(
[0] => box 1
[1] => box 2
[2] => box 3
[3] => box 4
[4] => box 5
)
To insert it into the database, you can just walk through the array.
I hope this helps.
Habtom