Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

problem with submitted data

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

problem with submitted data

Postby trompie » Mon May 05, 2003 5:15 am

I have a program where in the first file(distribution.php) teachers can be selected from multiple dropdownboxes (called teacher_0, teacher_1, teacher_2 etc...). No problem so far, but when I submit, in the second file(selected.php) I want to show the selected teachers. This doesn't seem to work... please help

distribution.php
--------------------
...
<form action="selected.php" method=post>
<table>
<?for ($x=0;$x<20;$x++){
$query2 = "select * from docentes order by doc_name";
$result2 = mysql_query($query2);
$count2 = mysql_numrows($result2);

$teacher = "teacher_".$x;
?>
<tr>
<td>
<select name=<? echo $teacher;?>>
<option>-------Select-------</option>
<?
for($y=0;$y<$count2;$y++){
$doc_name = mysql_result($result2, $y,"doc_name");
$doc_id = mysql_result ($result2, $y, "doc_id");
echo"<option value='$doc_id'>$doc_name</option>";
}
?>
</select>
</td>
</tr>
<?}?>
</table>
<input type=submit value=submit>
</form>
...


selected.php
----------------
...
<?
for($i=0;$i<20;$i++){

$selectedteacher='$teacher_'.$i;
$selectedteacher= addslashes($selectedteacher);

$query = "select * from docentes where doc_id='$selectedteacher'";
$result = mysql_query($query);
$count = mysql_numrows($result);
$doc_name = mysql_result($result, 0, "doc_name");
echo "this is the selected docent $i:";
echo "<input type=text value='$doc_name'><br>";
}
?>
trompie
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Apr 07, 2003 4:24 am

Postby mike » Mon May 05, 2003 8:30 am

I am not really sure but I came up with a similar problem like that. You are passing 19 variables to the 2nd file (teacher_#) and you want to use them all. That sounds ok but these variable must be used inside a loop. As I remember right you cannot pass increment variables inside a loop. Eg:

$var1 = "bla";
$var2 = "bla2";
$var3 = "bla3";

for($i=0;$i<=3;$i++){
echo "$var$i";
}


This wont work. But if you try store them in an array:

$var[1] = "bla";
$var[2] = "bla2";
$var[3] = "bla3";

for($i=0;$i<=3;$i++){
echo "$var[$i]";
}

will 100% work :) Hope you understood what is wrong ... dot have time to change your whole script :(
User avatar
mike
New php-forum User
New php-forum User
 
Posts: 73
Joined: Sun May 04, 2003 4:26 am
Location: Athens

Postby liquedus » Mon May 05, 2003 12:15 pm

reply to post above, he is using variable variables... so no need to use arrays.

try this also:

$count2 = mysql_numrows($result2);

make it

$count2 = mysql_num_rows($result2);

both your pages have this error... i will have a looksi again when I get back later
liquedus
php-forum Active User
php-forum Active User
 
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada

Postby mike » Mon May 05, 2003 1:12 pm

well sorry if I was misunderstood but was talking about the passing arguments (by the form) not the variable variables :)
User avatar
mike
New php-forum User
New php-forum User
 
Posts: 73
Joined: Sun May 04, 2003 4:26 am
Location: Athens

Postby liquedus » Mon May 05, 2003 5:57 pm

dont be sorry, maybe its me whos thinking of something else...

also to poster... if you are using dynamic variables this will not work:

$query = "select * from docentes where doc_id='$selectedteacher'";

change to:

$query = "select * from docentes where doc_id='$$selectedteacher'";

since dynamic variables require 2 $$
liquedus
php-forum Active User
php-forum Active User
 
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher, Yahoo [Bot] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.