View Single Post
Old 11-12-2007, 08:04 PM   #3 (permalink)
CoryMathews
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

I have been playin around with this for a couple days but cant seem to get it to work... this is the first time ive tried to do something like this in any language so that could be my problem. anyways heres what im workin with.

PHP Code:
if ($_POST['Submit']) {
   
$tablesArray = array('table1''table2''table3''table4''table5');
   
$checkTheseFieldsArray = array('pname''version''link');
   
$checkTheseFieldsLen count($checkTheseFieldsArray);
   
extract($checkTheseFieldsArray);
   
extract($tablesArray);
   
$tablesLen count($tableArray);
  
 
//create a date and time.
   
$date date("Y-m-d");
   
$time $_SERVER["REQUEST_TIME"];

 
//Tried using it the old fasioned way.
   
for ($x=0$x $tablesLen$x++) {
      if(!
$_POST[eval("\$tablesArray\[\$x\]")]) {
         
$tablesArray[$x] = "";
      } else {
         
$tablesArray[$x] = $_POST[$tablesArray[$x]]; }
      }

   
//Tried using foreach loop
   
foreach($checkTheseFieldsArray as $value2) {
      if(!
$_POST[$value2]) {
         
$value2 "";
      } else {
         
$value2 $_POST[$value2];  } }

   foreach(
$tablesArray as $value3) {
      if(${
$value3} != "") {
         
$sql=mysql_query("INSERT INTO $value3 (area1, area2 , area3 , area4)
         "
."VALUES ('NULL', '$pname', '$version', '$link')") or die(mysql_error()); 
} }
}


//Contine on to form if not submitted
ex 1 input field
Link

<
input name="link" type="text" size="28" maxlength="128" />

//And one example checkbox for the tables.
<input type="checkbox" name="table1" />Table 1 
As of now with real table values this inserts into all 5 of the tables instead of just the one defined (or checked).

Any Tips?
CoryMathews is offline  
Reply With Quote