[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Check Boxes

Posted on 2002-04-06
7
Medium Priority
?
244 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 46 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

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!

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

656 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