Hello all,
Still doing my best to get my head around some problems and so if what I suggest below is nonsense, please let me know.

The current problem is that I have a radio button form which, thanks to the coding, acts like a checkbox form because of what's happening in the name field

<table width="100%">
<tr>
<td colspan="3"><h3>Which level do you think you're currently are?</h3></td>
</tr>
<tr>
<td width="30%"><input type="radio" name="level[beginner]" id="beginner" value="1"/> 

Beginner</td>
<td width="30%"><input type="radio" name="level[intermediate]" id="intermediate" 

value="1"/> Intermediate</td>
<td width="30%"><input type="radio" name="level[advanced]" id="advanced" value="1"/> 

Advanced</td>
</tr>
</table>

I've tried removing the [] tags which makes the radio button work fine but then gives me lots of warnings:

Warning: Invalid argument supplied for foreach() on line 247
Warning: implode() [function.implode]: Invalid arguments on line 252
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER by teachers.ID DESC' at line 8

The lines this refers to is:

     foreach ($_POST['level'] as $key5=>$value)

  {
    if($value==1) $criteria[] = "teacherages.TeacherAges='$studentage' AND teacherlevel.TeacherLevel='".mysql_escape_string($key5)."' AND teachers.TypeLanguageTeacher='".mysql_escape_string($key4)."' AND teachersubject.TeacherSubject='$subject' ".$iscourse." ".$istown." ".$isdistrict." ".$isinvoice." AND teachers.County='".mysql_escape_string($county)."'";
}
   $criteria = implode(' OR ', $criteria);

In reference to ORDER by teachers.ID DESC, here is the code:

$query = "SELECT Distinct teachers.DatePosted,teachers.FirstName,teachers.ID,teachers.Name,teachers.Town,teachers.county,teachersubject.TeacherSubject,teachersubject.TeacherCourse
From teachers Join teacherprice on teachers.ID=teacherprice.TeacherID
join teacherlevel on teachers.ID=teacherlevel.TeacherID
Join teacheravailable on teachers.ID=teacheravailable.TeacherID
join teachersubject on teachers.ID=teachersubject.TeacherID
Join teacherages on teachers.ID=teacherages.TeacherID
WHERE $criteria
ORDER by teachers.ID DESC";

What would be the best solution here? Would it be to make the radio buttons in php or would there have to be changes in the back end programming?

Many thanks in advance for your help.

    For radio buttons to work as expected in html they must all have the same name. And only one value can ever be selected so no need to use arrays. So emit something like:

    <input type="radio" name="level" id="beginner" value="beginner"/>
    <input type="radio" name="level" id="intermediate" value="intermediate" />
    <input type="radio" name="level" id="advanced" value="advanced"/> 
    

    Note that I took out the table elements just for clarity. You still need them for formatting. Your post code should then switch on the value

      $level = $_POST['level'];
      switch($level)
      { 
        case 'beginner': $criteria = whatever; break;
        case 'intermediate': blah blah blah
      }
    

      Thanks for the reply, I'll hopefully get the chance to try it out in the next 24 hours or so (work ..... don't ask) so please forgive me if it takes a little time to report if everything is OK

        Not knowing much about php in general and this switch function is definitely new to me, I had a scoot around the internet trying to put two and two together.
        As far as I can tell, the case in php refers to "id" in the html code and the criteria in the php code refers to "name" in the html

        So based on that premise, I've got the following code:

        <?php
        echo ("<table width=100%><tr><td colspan=3><h3>Which level do you think you're currently are?</h3></td></tr>");
        echo ("<tr><td width=30%><input type='radio' name='level' id='beginner' value='1'/>Beginner</td><td width=30%><input type='radio' name='level' id='intermediate' value='1'/>Intermediate</td><td width=30%><input type='radio' name='level' id='advanced' value='1'/>Advanced</td></tr>");
        echo ("</table>");
        
          $level = $_POST['level'];
          switch($level)
          {
            case 'beginner': $criteria = 'beginner'; break;
            case 'intermediate': $criteria = 'intermediate'; break;
            case 'advanced': $criteria = 'advanced'; break;
          }
        
        ?>

        But it's still bringing up the implode warnings, which I think means I'm not getting the $criteria field correct.
        The data enters into the mysql databases as beginner, intermediate and advanced so i initially thought that should be the criteria.

        I then tried:

          $level = $_POST['level'];
          switch($level)
          {
            case 'beginner': $criteria = 'level[beginner]'; break;
            case 'intermediate': $criteria = 'level[intermediate]'; break;
            case 'advanced': $criteria = 'level[advanced]'; break;
          }

        the criteria being the "level" as originally coded, but this didn't work either.

        Am i missing something simple here or is this something major to do with the next page (which posts to the D😎 which has the criteria code:

         foreach ($_POST['level'] as $key5=>$value)
        
          {
            if($value==1) $criteria[] = "teacherages.TeacherAges='$studentage' AND teacherlevel.TeacherLevel='".mysql_escape_string($key5)."' AND teachers.TypeLanguageTeacher='".mysql_escape_string($key4)."' AND teachersubject.TeacherSubject='$subject' ".$iscourse." ".$istown." ".$isdistrict." ".$isinvoice." AND teachers.County='".mysql_escape_string($county)."'";
        }
           $criteria = implode(' OR ', $criteria);

          Your best bet might be to take a few weeks and work through some of the php/mysql tutorials. You appear to be trying to modify a not particularity well written script without understanding much of what it is doing.

          If you really want to continue down your current path then manually write out and test enough of your query so you know what the where clause needs to look like. You can then work backwards to see how to generate it.

          Basic problem is the the script as posted implies that any combination of beginner/intermediate/advanced can be chosen. However the choice of radio boxes (as opposed to check boxes) implies that you only want one choice.

          So you really need to figure out just what you want the script to do before trying to implement it.

            I know what it what meant to do - select one option if you're beginner, intermediate or advanced.

            My developer however has created something else and left me in the doo-dah and I'm trying to sort out the issues by myself. A lot of it I've done myself, some with help, but I agree with you that I'd probably need some professional help (mentally as well probably)

              Write a Reply...