[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Check Boxes

Posted on 2002-04-06
7
Medium Priority
?
246 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
Technology Partners: 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.
Suggested Courses
Course of the Month18 days, 21 hours left to enroll

834 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