Jump to content


a little php help


2 replies to this topic

#1 CoryMathews

    P2L Jedi

  • Members
  • PipPipPip
  • 554 posts
  • Gender:Male
  • Location:Texas

Posted 12 November 2007 - 03:08 PM

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.

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?

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 12 November 2007 - 09:26 PM

Out of curiosity, what is the point of this:
if(!$_POST[eval("\$tablesArray\[\$x\]")])
I'm personally amazed anybody would think to do something like that, but i'm willing to here reason... doubt i'll accept it, but still willing...

But until that time is met, i have to ask, what is this? If you were talking about OOP, i could give a rough definition... but here, i'm clueless (might be my stuborn refusal to read code that i don't know the purpose of though...).

Disclaimer: If this comes off in anyway rude, i appologize, i'm just feeling kinda sarcastic at the moment (being reading about John Locke's political views :ninja:).

#3 CoryMathews

    P2L Jedi

  • Members
  • PipPipPip
  • 554 posts
  • Gender:Male
  • Location:Texas

Posted 13 November 2007 - 08:42 AM

that line because i was trying to get the value of whats in tablesArray[x] not just tablesArray[x] value. Meaning if tablesArray[x] was table1 i want the value of $table1. that what i was tryin to do.

I dont rememeber how i got there i was tryin a whole buntch of different things and couldnt get any of them to work.

The entire code is supposed to take the values of checkFieldsArray and place them into the correct table in tablesArray depending on which ones i check in the form.

Problem is when im trying to do.. what i said in my first paragraph of this post. Its not getting the value of the value.. if that makes any sense.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users