View Full Version : I need help with passing arrays of html forms to script in php
gsamper
12-07-2002, 07:00 PM
Well i have some problems when i pass the values of arrays in html forms.
My code is:
<?PHP
include("Login.php");
session_start();
session_register("MSG_ERROR");
$connect2 = odbc_connect("BD","","");
if( !$connect2 ){
echo "Error en la conexion a la base de datos";
exit;}
$con2="SELECT * FROM Partidas WHERE partidas.co_number=". "'$Pedi1'" . "and Partidas.Genero=". "'$val7'";
$consulta2 = odbc_exec( $connect2, $con2);
if( !$consulta2 ){
echo " Error en la consulta a la tabla Partidas";
exit;}
echo '
<TABLE BORDER=0>
$x=0;
while( odbc_fetch_row( $consulta2 ) ){
$val8=odbc_result( $consulta2 , 1 );
$val9=odbc_result( $consulta2 , 2 );
echo "<TR>";
echo '<TD><INPUT TYPE="TEXT" NAME="id_par[]" SIZE="14" VALUE="';echo $val8;echo '" onFocus="this.blur()"></TD>';
echo '<TD><INPUT TYPE="TEXT" NAME="par['.$x.']" SIZE="5" VALUE="';echo $val9;echo '" onFocus="this.blur()"></TD>';
echo "</TR><BR>";
$x = $x + 1;
}
echo '
</TABLE><BR><BR>
<CENTER>
<INPUT TYPE="SUBMIT" VALUE="Continuar>>" name="DONE">
</CENTER>
</FORM>
</FONT>
</BODY>
</HTML>';
?>
This code works fine and generates 15 inputs but when a try to read the values from arrays it's only have 10 values. I don't know the reason.
the script where i try to read the values is:
<?PHP
include("Login.php");
session_start();
session_register("MSG_ERROR");
$id_par[] = $_REQUEST['id_par'];
$par[] = $_REQUEST['par'];
for ($i = 0; $i <sizeof($id_par); $i++) {
echo $id_par[$i] . "-i:" . $i;
echo "<BR>";
}
?>
And i have only 10 values. Somebady help me!! :(
ConfusedOfLife
12-07-2002, 09:32 PM
Hi! how're ya?! First of all, I'd like to say that I don't know anything about odbc and even though it looks like mySql, but I still wana reserve the right to be wrong!
Saying that, I quote some parts of your code that I think have some problems or could have been written better ( my personal idea of course! )
You said that you have 10 indices of your array availabe to you, so, probably what I say is wrong, but in MySQL after writing mysql_connect( "host", "username", "password"), then we have to write mysql_select_db( "db_name");, that I do not see something similiar for odbc.
echo '<TD><INPUT TYPE="TEXT" NAME="id_par[]" SIZE="14" VALUE="';echo $val8;echo '" onFocus="this.blur()"></TD>';
echo '<TD><INPUT TYPE="TEXT" NAME="par['.$x.']" SIZE="5" VALUE="';echo $val9;echo '" onFocus="this.blur()"></TD>';
in your value parts, you are using an unfamiliar syntax to me! I think you should write
<input value='<?=$val8?>' >
or if short tags ain't supported :
<input value='<?PHP print $val8 ?>' >
And using a for loop when you can use a foreach in your reader script value isn't probably a good idea, since you always might encounter an unexpected index.
gsamper
12-09-2002, 02:19 PM
Hi!!
Yes i don't write the sentence of connection, because i did't want to write a lot of lines of code.
I probed with foreach but i'm still having the same result.
And the sentences that you told me, is a bit diferent but that works with 9 values not more.
That is the thing that i don't understand.
But I really apreciate your help. Thanks!
ConfusedOfLife
12-11-2002, 07:30 AM
Well, if nothing helps and you still want help! post your db rows and say what you want, I write something and then we can compare it with each other and one of them will work I think!
PS: regarding that thank you, you're welcome!
gsamper
12-11-2002, 02:20 PM
Well, I found that arrays was not the problem. :) . I did a test with less values and arrays worked fine. I was thinking that the problem is the amount of values that php support and i was modifiyinf the php.ini file in order to find some parameter that indicate the amount of values. But i didnīt. And I'm still having the problem. Do you know somwething about it?
:(
ConfusedOfLife
12-12-2002, 07:34 PM
I don't think that you ever have such a problem ( maybe I'm wrong!), but PHP is very strong and I don't think that it limits you to use special number of values!
gsamper
12-13-2002, 02:54 PM
First, How are you?
Well in fact i'm still having the problem, but i found another way. I'm going to explain the scene.
The script generates 8 input forms and each input have 15 values in the array. If a try whit all input's the php don't pass all the values, and if i try with less values that works fine. That is the reason that i thing php is the problem.
I hope i could explain myself, because my english is not very good.
Thanks.
ConfusedOfLife
12-13-2002, 04:54 PM
Hi gsamper, thanx, I'm fine! how're ya doin'?
Well, I decided to look at your code thouroughly and even though I don't know anything about odbc , but I looked up the functions that you used in php mans and I found that even though some of them, like fetch_row really look like their counter parts in mySql, but they're structure is totally different ( odbc_fetch_row returns a boolean, while mysql_fetch_row returns an array) and I also learned that instead of having odbc_query we have odbc_exec. So, I parsed your code! and I changed it in this way, if it doesn't work, then I think you have to post your odbc table too and I'm afraid we have to ask for some other members to look at the code too ( I'm just a beginner!)
Here's the redo of your first code :
<?PHP
include("Login.php");
session_start();
session_register("MSG_ERROR");
$connect2 = odbc_connect("BD","","") or die("Error en la conexion a la base de datos");
$con2="SELECT * FROM Partidas WHERE partidas.co_number='$Pedi1' and Partidas.Genero='$val7'";
$consulta2 = odbc_exec( $connect2, $con2) or die(" Error en la consulta a la tabla Partidas");
# You forgot to put a form in your document!
# Don't forget to complete the action if your
# action page isn't the current page.
print "<form method='POST' action=''>\n"
print " <TABLE BORDER=0>\n";
$x=0;
while( odbc_fetch_row( $consulta2 ) )
{
$val8=odbc_result( $consulta2 , 1 );
$val9=odbc_result( $consulta2 , 2 );
echo " <TR>\n";
echo ' <TD><INPUT TYPE="TEXT" NAME="id_par[]" SIZE="14" VALUE="$val8" onfocus="this.blur()"></TD>';
echo ' <TD><INPUT TYPE="TEXT" NAME="par[$x]" SIZE="5" VALUE="$val9" onFocus="this.blur()"></TD>';
echo " </TR><BR>\n";
$x = $x + 1;
}
?>
</TABLE><BR><BR>;
<CENTER>
<INPUT TYPE="SUBMIT" VALUE="Continuar>>" name="DONE">
</CENTER>
</FORM>
</FONT>
</BODY>
</HTML>';
You noticed that you even forgot to open the <form> tag in your script! Now I'm wondering why you even got those 10 values without a form!
Here's what I came up with when I worked on your second code :
<?PHP
include("Login.php");
session_start();
session_register("MSG_ERROR");
$id_par[] = $_REQUEST['id_par'];
$par[] = $_REQUEST['par'];
$i = 0;
foreach ( $id_par as $_REQUEST['id_par'])
echo $id_par . " -i " . ($i++) . "<br>\n";
?>
Hope that it helps.
PS: About your english : we're in the same boat!
gsamper
12-13-2002, 05:08 PM
Jajajaja, well but we had understood very well. And about the code in fact i have the <Form> sentence, but i don't put it in order to save lines of code, because the script have about 1480 lines of code, but if you want to review all the code I can put it.
I expose the problem in the forum, but nobody answer.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.