Page 1 of 1

help with two dimensional array

Posted: Thu Feb 23, 2006 6:37 am
by ddragas
how to post values from textfields to recive them and isert them into two dimensional array


Untill now I have this, bit it is not working.

Code: Select all

<?

if(isset($_POST['Submit']))
	{
		$a=0;
		$data=array();
		foreach ($_POST as $fieldName => $value)
		 {
				if($fieldName == 'broj')
					{
						$broj = $value;
					}

				   if ($fieldName != 'broj' && $fieldName != 'Submit') 
				   {
					   if($fieldName == "ime$a")
							{
							   $value_ime = $value;
							}
						if($fieldName == "prezime$a")	
							{
								$value_prezime = $value;
							}
						
						
						$data[]=array($value_ime, $value_prezime);
						
					$a=$a+1;
					}
		
		}
	echo "Ukupno " . $broj . " polja.";
	print_r($data);
	}

		else
	{

	$m = 3;
		
		//$ime = array();
		//$prezime = array();
		echo "<br>";
		echo "<form enctype=\"multipart/form-data\" action=\"\" method=\"POST\">";
		echo "<table width=\"80%\"  border=\"0\" align=\"center\" bordercolor=\"#000000\">";
		echo "<input type=\"hidden\" name=\"broj\" value=\"$m\">";
		for ($i=0; $i < $m; $i++)
      	{
	  		$broj = $i+1;
      		echo"<td width=\"40%\" align=\"right\">" . "Slika " . $broj . ": " ."</td><td>"; 
			echo "<input type=text name=ime" . $i . ">";
			echo "</td>";
			echo "<td>";
			echo "<input type=text name=prezime" . $i . ">";
			echo "</td>";
		    echo "</tr>";
      	}
		echo "<td></td></tr>";
        echo "<td></td><td><input type=\"submit\" name=\"Submit\" value=\"Pridruži / izmjeni slike\" onclick=\"value='Molim pri&#269;ekajte...'\" class=\"txt\">";
        echo "<input name=\"Reset\" type=\"reset\" id=\"Reset\" value=\"Poništi\" class=\"txt\"></td></tr>";
	   
		echo "</table>";
		echo "</form>";
	}
?>

Posted: Thu Feb 23, 2006 9:48 am
by ddragas
Hope U understand what I need help with?


there can be X number of text fields with name and surname
posts from form text fields like:

NAME SURNAME

Mark Johnson
Piter Young
Andy Hofner

etc....


I need to insert values from text fields into db.

Insert into users (name, surname) VALUES ('$name', '$surname')

What is easyest way to do this.

I tought first to put values from text fields into two dimensional array, retrive data from array and put them into db.

If I'm doing something wrong, please point me in right way

Posted: Thu Feb 23, 2006 9:50 am
by pickle
How is it not working? What does $data get?

Posted: Thu Feb 23, 2006 9:52 am
by ddragas
Here is resoult of array

Code: Select all

Ukupno 3 polja.Array
(
    [0] => Array
        (
            [0] => Petar
            [1] => 
        )

    [1] => Array
        (
            [0] => Petar
            [1] => 
        )

    [2] => Array
        (
            [0] => Petar
            [1] => 
        )

    [3] => Array
        (
            [0] => Petar
            [1] => 
        )

    [4] => Array
        (
            [0] => Petar
            [1] => 
        )

    [5] => Array
        (
            [0] => Petar
            [1] => 
        )

)