Solved

Check Boxes

Posted on 2002-04-06
7
207 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Is there a limit to how many inner joins you should use? 4 33
javascript: add id amounts 5 47
AWS EC2 & RDS Instance 5 36
Google Maps API and PHP 25 34
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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.

823 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