Can´t process variables from java interactive forms with php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
InSion
Forum Newbie
Posts: 11
Joined: Thu Oct 21, 2004 7:20 am

Can´t process variables from java interactive forms with php

Post by InSion »

I have a form which is used to insert thing to a mysql database... Some items are fixed, like name and address but other, like telephone numbers and e-mails can be none, one or more so I make an add button to allow to insert input fields in a "span position:relative". It works ok but when I submit the form i can't get those inputs (i.e. $_POST["telefono1"] isn´t set when it should be) :( .

Here I send you some code, first of all the javascript function:

Code: Select all

function addTel(number) {
	totaltel = totaltel + number;
    telfield = ""; 
    if (number < 16 && number > -1) {
      for (i=1; i <= number; i++) {
        if (totaltel > 1) {telfield = telfield + "<br>"; }
		telfield += "(" + "<? echo menuCaracTel("+ totaltel +",1); ?>" + ")";
		telfield += " <input type='text' size='30' maxlength='70' name='telefono" + totaltel + "'>";
      }
      if (document.layers) {
        document.layers.fieldtel.document.write(telfield);
        document.layers.fieldtel.document.close();
      }
      else {
        if (document.all) {
          fieldtel.innerHTML += telfield;
        }
      }
    }
    else {
      window.alert("Please select up to 15 entries.");
   }
  }
Note : ELSE is not working 'couse number parameter is always 1.
Note 2: menuCaracTel() is a PHP functions that makes a dropdown menu with telephone prefixes. Also, names are in spanish.

After submit PHP should insert phones in tables here:

Code: Select all

$numtel = 1;
    $tel = 'telefono'.$numtel;
	while (isset($_POST[$tel])) {
	  $IDtelefono = nuevoId("IDtelefono","telefonos");
	  $tipo = 'T';
	    $carac = 'caractel'.$numtel;
	  $caracteristica = $_POST[$carac];
	  $numero = $_POST[$tel];
	  $descripcion = '';
	  $sql3 = "INSERT INTO telefonos VALUES ($IDtelefono,'$tipo',$caracteristica,$numero,$descripcion)";
	  mysql_query($sql3);
	  $sql4 = "INSERT INTO lista-telefonos VALUES ($IDcentro,$IDtelefono)";
	  mysql_query($sql4);
	  $numtel++;
	  $tel = 'telefono'.$numtel;
	}
'While' is obbvied 'couse no telephone variable is set, the normal inputs of the form are inserted in others table with no problem...

I wish you can help me, I think the problem is that the inputs are seen but not passed through $_POST data, probably I should make this in another way, don´t know. Thank you very much.

:roll: YESS!! you´ll help will be VERY appreciated... :wink:
InSion
Forum Newbie
Posts: 11
Joined: Thu Oct 21, 2004 7:20 am

is it possible?

Post by InSion »

none? anybody know if is possible to do what I want to?.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

In your javascript, shouldn't

Code: Select all

telfield += "&nbsp;<input type='text' size='30' maxlength='70' name='telefono" + totaltel + "'>";
be

Code: Select all

telfield += "&nbsp;<input type='text' size='30' maxlength='70' name='telefono" + i + "'>";
InSion
Forum Newbie
Posts: 11
Joined: Thu Oct 21, 2004 7:20 am

Post by InSion »

No, it´s ok, that for really doesn´t work because AddTel is always called with numer = 1 and totaltel is the variable that stores the total telephonic numbers added and works as an ID.

Today I found some problems with my PHP code in lines 3,7,8,10.

when I called $_POST[$tel] I should say $_POST["$tel"]. Similarly in line 10, i forgot some '' next to variables for the mysql_sentence, now it´s working better but $caracteristica is still not sotred in database I think I still make some grammatic mistakes so I will continu checking, thank you very much
Post Reply