Solved

Check Boxes

Posted on 2002-04-06
7
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

733 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