Solved

Check Boxes

Posted on 2002-04-06
7
187 Views
Last Modified: 2008-03-06
i have two files.
this is the first one:
authority_process.php
-------
<html>
<table border="1" width="100%" bordercolor="#FFFFFF">
<form action="authority_send_emails.php" method="POST">
<?
   // link to the database
   $linkID = mysql_connect("localhost","","");
   $result = mysql_select_db("test_toaster",$linkID);

   $condition = $Submit && ($Subjects != "Choose one");
   if ($condition) {
   $selected = mysql_query("SELECT id FROM subject WHERE name='$Subjects'", $linkID);
   $selected_subject_id = mysql_fetch_array($selected);
   $selected_subject_id = $selected_subject_id["id"];
   $table_teaches = mysql_query("SELECT instructor_id FROM teaches WHERE subject_id='$selected_subject_id'", $linkID);
   if ($table_teaches != "")
   $teaches_rows_num = mysql_num_rows($table_teaches);
   if ($teaches_rows_num == 0)
       echo "NO instructors teach this subject";
   else{
     for ($num=0 ; $num < $teaches_rows_num ; $num++)
    {
    $teaches = mysql_fetch_array($table_teaches);
?>
    <tr>
    <td width="100%">
    <INPUT NAME="Check[<? echo $num ?>]" TYPE="CHECKBOX" VALUE="<? echo $num  ?>">
<?
    $instID = $teaches["instructor_id"];
    $table_instructor = mysql_query("SELECT fullname FROM instructor WHERE id='$instID'", $linkID);
    $name = mysql_fetch_array($table_instructor);
    $name[$num] = $name["fullname"];
    echo $name[$num] ?>
    </td>
    </tr>
<?
}//end for
?>
  <tr>
    <td width="100%">
        <p><input type="submit" value="Submit" name="B1"></p>
      </form>
    </td>
  </tr>
</table>
<?
}//end else
}//end if ($condition)
?>
</html>
------------------
------------------
and this is the 2nd one:
authority_send_emails.php
------------------
<?php
     for ($num=0 ; $num < $teaches_rows_num ; $num++){
     if ($Check[$num] == "$num")
     echo $name[$num];
}
?>
------------------

the problem that the variable $name is not recognizied!
0
Comment
Question by:almaha
  • 3
  • 2
  • 2
7 Comments
 
LVL 32

Expert Comment

by:Batalf
ID: 6922967
The $name is not recognized in authority_send_emails ??

I can't find any form-fields with the name="name[]" in authority_process.php. That's probably your problem.

The only field I could find is Check[]

Maybe you need a hidden-field in authority_process.php?

<input type="hidden" Name="name[<? echo $num ?>]" value="<? echo $name[$num]; ?>">

 
0
 

Author Comment

by:almaha
ID: 6923053
the following is more easy to understand and know what's i'm stuck in:
--------------------------------
<html>
<table border="1" width="100%" bordercolor="#FFFFFF">
<form action="authority_send_emails.php" method="POST">
<?
   // link to the database
   $linkID = mysql_connect("localhost","","");
   $result = mysql_select_db("test_toaster",$linkID);

   $condition = $Submit && ($Subjects != "Choose one");
   if ($condition) {
   $selected = mysql_query("SELECT id FROM subject WHERE name='$Subjects'", $linkID);
   $selected_subject_id = mysql_fetch_array($selected);
   $selected_subject_id = $selected_subject_id["id"];
   $table_teaches = mysql_query("SELECT instructor_id FROM teaches WHERE subject_id='$selected_subject_id'", $linkID);
   if ($table_teaches != "")
   $teaches_rows_num = mysql_num_rows($table_teaches);
   if ($teaches_rows_num == 0)
       echo "NO instructors teach this subject";
   else{
     for ($num=0 ; $num < $teaches_rows_num ; $num++)
    {
    $teaches = mysql_fetch_array($table_teaches);
?>
    <tr>
    <td width="100%">
    <INPUT NAME="Check[<? echo $num; ?>]" TYPE="CHECKBOX" VALUE="<? echo $num;  ?>">
<?
    $instID = $teaches["instructor_id"];
    $table_instructor = mysql_query("SELECT fullname FROM instructor WHERE id='$instID'", $linkID);
    $name = mysql_fetch_array($table_instructor);
    $name[$num] = $name["fullname"];
    echo $name[$num];
    //if ($Check[$num] == "$num")
    //echo $name[$num];
    echo $Check[$num];   <<<<<<<<<<<< THIS LINE
?>
    </td>
    </tr>
<?
}//end for
?>
  <tr>
    <td width="100%">
        <p><input type="submit" value="Submit" name="Submit"></p>
      </form>
    </td>
  </tr>
</table>
<?
}//end else
}//end if ($condition)
?>
</html>
-------------------------------
i have a problem with this line >> echo $Check[$num];
it doesn't recognize the variable $Check !
0
 
LVL 32

Expert Comment

by:Batalf
ID: 6923076
Instead of

   $name[$num] = $name["fullname"];
   echo $name[$num] ?>

why don't simply type

echo $name["fullname"];

?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 5

Expert Comment

by:harwantgrewal
ID: 6923560
I think you are mistaking somewhere instead try to use of array like check[<?echo $num?>] will not create an array it will create a variable like check[1] but this is not a array try to use like this

check<?echo $num?> this will generate variables check1, check2 etc and make a hidden field which calculates the number of check boxes and the in for loop you can retive the the variables like
$chk="check".$num;
echo $$chk;

Harry
0
 
LVL 5

Accepted Solution

by:
harwantgrewal earned 23 total points
ID: 6927936
did your problem solved
0
 
LVL 32

Expert Comment

by:Batalf
ID: 6927944
Harry:

About:
"I think you are mistaking somewhere instead try to use of array like check[<?echo $num?>] will not create
an array it will create a variable like check[1] but this is not a array"

Are you sure about this? I don't think so, I have used this a lot of times, and it's easy to loop through the array afterwards. check[<? echo $num; ?>] WILL CREATE A ARRAY.

Batalf
0
 

Author Comment

by:almaha
ID: 6933755
Problem unsolved :| EOS i'm movin to another procesture!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now