php - mysql insert question/problem.
Posted: Sat Sep 20, 2008 1:17 am
All i am trying to do is insert values into a table.The part which is confusing me is that i am trying to do it for any number of fields and not knowing what those fields might be called (if that makes sense).
I was wondering if anyone had a good way to do this.
I am using this snippet of code to get the headers of the table and print them on the screen with a input box for each.
code:
#include 'opendb.php';
$getFields = mysql_query("SHOW COLUMNS FROM table");
if(!$getFields) {
echo 'could not run query: ' . mysql_error();
exit;
}
if(mysql_num_rows($getFields) > 0) {
while($field = mysql_fetch_assoc($getFields)) {
echo $field["Field"];
echo '<input type="text" name="'.$field[Field].'" value="" />';
}
}
if($_POST) {
// not sure what should be here to catch and insert.
}
What do i put into the if($_POST) for the page to INSERT correctly. I have a submit button on the page which posts back to the same page.
Any help/advice would be great.
Just Solved it.
Made two arrays and did an insert.
I was wondering if anyone had a good way to do this.
I am using this snippet of code to get the headers of the table and print them on the screen with a input box for each.
code:
#include 'opendb.php';
$getFields = mysql_query("SHOW COLUMNS FROM table");
if(!$getFields) {
echo 'could not run query: ' . mysql_error();
exit;
}
if(mysql_num_rows($getFields) > 0) {
while($field = mysql_fetch_assoc($getFields)) {
echo $field["Field"];
echo '<input type="text" name="'.$field[Field].'" value="" />';
}
}
if($_POST) {
// not sure what should be here to catch and insert.
}
What do i put into the if($_POST) for the page to INSERT correctly. I have a submit button on the page which posts back to the same page.
Any help/advice would be great.
Just Solved it.
Made two arrays and did an insert.