Radio buttons not showing values from database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lozwaldo
    New Member
    • Feb 2008
    • 37

    Radio buttons not showing values from database

    Hi All
    I'm a noob and wanted to show records from my db with one field using radio buttons. Problem is that I can't get the values from the table to check the appropriate radio button.

    Any help MUCH appreciated

    Cheers :)
    [php]
    $sponsored = ('IsSponsored' == 1)?"checked" : "";
    $notsponsored = ('IsSponsored' == 0)?"" : "checked";

    while($show = mysql_fetch_arr ay( $result )) {
    // Print out the contents of each row into a table
    echo "<tr> <td>";
    echo $show['ChildID'];
    echo "</td> <td >";
    echo $show['givenName'];
    echo "</td> <td>";
    echo $show['gender'];
    echo "</td> <td>";
    echo $show['countryName'];
    echo "</td> <td>";
    echo $show['favouritePlay'];
    echo "</td> <td>";

    /*this box checked if IsSponsored = 1*/
    echo "<input type=\"radio\" name=\"".$show['ChildID']." 'IsSponsored'\" value=\"1\" ".$sponsored."> ";

    echo "</td> <td>";

    /*this box checked if IsSponsored = 0*/
    echo "<input type=\"radio\" name=\"".$show['ChildID']." 'IsSponsored'\" value=\"0\" ".$notsponsored .">";


    echo "</td> <td>";
    echo $show['dateOfBirth'];
    echo "</td> </tr>";
    }[/php]

    Use the appropriate code tags around your code - moderator
    Last edited by ronverdonk; Feb 26 '08, 11:52 AM. Reason: code within code tags
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    What is IsSponsored?

    Comment

    • lozwaldo
      New Member
      • Feb 2008
      • 37

      #3
      Originally posted by hsriat
      What is IsSponsored?
      IsSponsored is a field in table

      Has value of "1" or "0"

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        [php]$sponsored = array("";"check ed");
        $not_sponsored = array("checked" ;"");
        while($show = mysql_fetch_arr ay( $result )) {
        // Print out the contents of each row into a table
        echo "<tr> <td>";
        echo $show['ChildID'];
        echo "</td> <td >";
        echo $show['givenName'];
        echo "</td> <td>";
        echo $show['gender'];
        echo "</td> <td>";
        echo $show['countryName'];
        echo "</td> <td>";
        echo $show['favouritePlay'];
        echo "</td> <td>";

        /*this box checked if IsSponsored = 1*/
        echo "<input type=\"radio\" name=\"".$show['ChildID']." \" value=\"1\" ".$sponsore d[$show['IsSponsored ']]."></input>Is sponsored";

        echo "</td> <td>";

        /*this box checked if IsSponsored = 0*/
        echo "<input type=\"radio\" name=\"".$show['ChildID']." ''\" value=\"0\" ".$not_sponsore d[$show['IsSponsored ']]."></input>Is not sponsored";

        echo "</td> <td>";
        echo $show['dateOfBirth'];
        echo "</td> </tr>";
        }[/php]

        Check this... is this what you wanted or not?

        Comment

        • lozwaldo
          New Member
          • Feb 2008
          • 37

          #5
          Originally posted by hsriat
          [php]$sponsored = array("";"check ed");
          $not_sponsored = array("checked" ;"");
          while($show = mysql_fetch_arr ay( $result )) {
          // Print out the contents of each row into a table
          echo "<tr> <td>";
          echo $show['ChildID'];
          echo "</td> <td >";
          echo $show['givenName'];
          echo "</td> <td>";
          echo $show['gender'];
          echo "</td> <td>";
          echo $show['countryName'];
          echo "</td> <td>";
          echo $show['favouritePlay'];
          echo "</td> <td>";

          /*this box checked if IsSponsored = 1*/
          echo "<input type=\"radio\" name=\"".$show['ChildID']." \" value=\"1\" ".$sponsore d[$show['IsSponsored ']]."></input>Is sponsored";

          echo "</td> <td>";

          /*this box checked if IsSponsored = 0*/
          echo "<input type=\"radio\" name=\"".$show['ChildID']." ''\" value=\"0\" ".$not_sponsore d[$show['IsSponsored ']]."></input>Is not sponsored";

          echo "</td> <td>";
          echo $show['dateOfBirth'];
          echo "</td> </tr>";
          }[/php]

          Check this... is this what you wanted or not?
          Sorry but tried this and page wouldn't run.

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            Originally posted by lozwaldo
            Sorry but tried this and page wouldn't run.
            isSponsored is a field in database, right?

            And is there any error?

            Comment

            • lozwaldo
              New Member
              • Feb 2008
              • 37

              #7
              Originally posted by hsriat
              isSponsored is a field in database, right?

              And is there any error?
              "IsSponsore d" is a field in the database

              This page is returning a query from another page. When this page tries to display the results the browser comes back with the generic "The page cannot be displayed" message. Here is all the code from the page.

              many thanks


              /////////////////////////////////////////////////////////////////////////////////////////////////////

              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
              <html xmlns="http://www.w3.org/1999/xhtml">
              <head>
              <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
              <title>Admin</title>
              </head>

              <body>

              <?php
              $link ="<br><br><a href='searchpag e.php'>Click here to go back to the search page.</a>";

              $countryName = $_POST['countryName'];
              $gender = $_POST['gender'];
              $ChildID = $_POST['ChildID'];


              //Just checking that values are being submitted properly
              echo $countryName;
              echo"<br>";
              echo $gender;
              echo"<br>";
              echo $ChildID;
              echo"<br>";

              $db = mysql_connect(' localhost', 'xxxx', 'xxxxx');
              mysql_select_db ("child",$db );

              if ($ChildID != "")
              {$query ="SELECT * FROM child.child
              where (countryName = '$countryName') and (gender ='$gender') and

              (ChildID ='$ChildID')";
              }else{
              $query ="SELECT * FROM child.child
              where (countryName = '$countryName') and (gender ='$gender')";
              }


              $result = mysql_query($qu ery);
              if (mysql_num_rows ($result) == 0) {
              echo "sorry, no matching results.";
              echo $link;
              exit;
              }


              echo "<table border='1' >";
              echo "<tr><th>ChildI D</th>
              <th>givenName </th>
              <th>gender</th>
              <th>countryName </th>
              <th>favouritePl ay</th>
              <th>Sponsored </th>
              <th>Not Sponsored</th>
              <th>dateOfBirth </th>
              </tr>";
              // keeps getting the next row until there are no more to get


              $sponsored = array("";"check ed");

              $not_sponsored = array("checked" ;"");

              while($show = mysql_fetch_arr ay( $result )) {

              /*Print out the contents of each row into a table*/

              echo "<tr> <td>";
              echo $show['ChildID'];
              echo "</td> <td >";
              echo $show['givenName'];
              echo "</td> <td>";
              echo $show['gender'];
              echo "</td> <td>";
              echo $show['countryName'];
              echo "</td> <td>";
              echo $show['favouritePlay'];
              echo "</td> <td>";

              /*this box checked if IsSponsored = 1*/
              echo "<input type=\"radio\" name=\"".$show['ChildID']." \" value=\"1\" ".$sponsore d[$show['IsSponsored ']]."></input>Is sponsored";
              echo "</td> <td>";

              /*this box checked if IsSponsored = 0*/
              echo "<input type=\"radio\" name=\"".$show['ChildID']." ''\" value=\"0\" ".$not_sponsore d[$show['IsSponsored ']]."></input>Is not sponsored";
              echo "</td> <td>";
              echo $show['dateOfBirth'];
              echo "</td> </tr>";
              }

              echo "</table>";

              ?>

              </body>
              </html>

              Comment

              • hsriat
                Recognized Expert Top Contributor
                • Jan 2008
                • 1653

                #8
                The code seems to be fine, the problem may be with the file name or directory.

                Comment

                • lozwaldo
                  New Member
                  • Feb 2008
                  • 37

                  #9
                  Originally posted by hsriat
                  The code seems to be fine, the problem may be with the file name or directory.
                  stupid IE
                  Firefox returned this error
                  "PHP Parse error: syntax error, unexpected ';', expecting ')' in C:\Inetpub\wwwr oot\practice\ch ildc.php on line 63"

                  am looking into this now

                  Comment

                  • hsriat
                    Recognized Expert Top Contributor
                    • Jan 2008
                    • 1653

                    #10
                    Originally posted by lozwaldo
                    stupid IE
                    Firefox returned this error
                    "PHP Parse error: syntax error, unexpected ';', expecting ')' in C:\Inetpub\wwwr oot\practice\ch ildc.php on line 63"

                    am looking into this now
                    oops...
                    My fault...
                    Array fields are separated with comma, not semicolon!
                    Like this...
                    $sponsored = array("","check ed");
                    $not_sponsored = array("checked" ,"");

                    Comment

                    • lozwaldo
                      New Member
                      • Feb 2008
                      • 37

                      #11
                      Originally posted by hsriat
                      oops...
                      My fault...
                      Array fields are saperated by comma, not semicolon!
                      Like this...
                      $sponsored = array("","check ed");
                      $not_sponsored = array("checked" ,"");
                      sorry.......
                      another error

                      Undefined index: IsSponsored in C:\Inetpub\wwwr oot\practice\ch ildc.php on line 83

                      Undefined index: IsSponsored in C:\Inetpub\wwwr oot\practice\ch ildc.php on line 87

                      Comment

                      • hsriat
                        Recognized Expert Top Contributor
                        • Jan 2008
                        • 1653

                        #12
                        Originally posted by lozwaldo
                        sorry.......
                        another error

                        Undefined index: IsSponsored in C:\Inetpub\wwwr oot\practice\ch ildc.php on line 83

                        Undefined index: IsSponsored in C:\Inetpub\wwwr oot\practice\ch ildc.php on line 87
                        remove the space after IsSponsored (in line 83 and 87) and check its spelling against the one in the db.

                        Comment

                        • Markus
                          Recognized Expert Expert
                          • Jun 2007
                          • 6092

                          #13
                          Use code tags
                          [php]
                          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

                          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                          <html xmlns="http://www.w3.org/1999/xhtml">
                          <head>
                          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                          <title>Admin</title>
                          </head>

                          <body>

                          <?php
                          $link ="<br><br><a href='searchpag e.php'>Click here to go back to the search page.</a>";

                          $countryName = $_POST['countryName'];
                          $gender = $_POST['gender'];
                          $ChildID = $_POST['ChildID'];


                          //Just checking that values are being submitted properly
                          echo $countryName;
                          echo"<br>";
                          echo $gender;
                          echo"<br>";
                          echo $ChildID;
                          echo"<br>";

                          $db = mysql_connect(' localhost', 'xxxx', 'xxxxx');
                          mysql_select_db ("child",$db );

                          if ($ChildID != "")
                          {$query ="SELECT * FROM child.child
                          where (countryName = '$countryName') and (gender ='$gender') and

                          (ChildID ='$ChildID')";
                          }else{
                          $query ="SELECT * FROM child.child
                          where (countryName = '$countryName') and (gender ='$gender')";
                          }


                          $result = mysql_query($qu ery);
                          if (mysql_num_rows ($result) == 0) {
                          echo "sorry, no matching results.";
                          echo $link;
                          exit;
                          }


                          echo "<table border='1' >";
                          echo "<tr><th>ChildI D</th>
                          <th>givenName </th>
                          <th>gender</th>
                          <th>countryName </th>
                          <th>favouritePl ay</th>
                          <th>Sponsored </th>
                          <th>Not Sponsored</th>
                          <th>dateOfBirth </th>
                          </tr>";
                          // keeps getting the next row until there are no more to get


                          $sponsored = array("";"check ed");

                          $not_sponsored = array("checked" ;"");

                          while($show = mysql_fetch_arr ay( $result )) {

                          /*Print out the contents of each row into a table*/

                          echo "<tr> <td>";
                          echo $show['ChildID'];
                          echo "</td> <td >";
                          echo $show['givenName'];
                          echo "</td> <td>";
                          echo $show['gender'];
                          echo "</td> <td>";
                          echo $show['countryName'];
                          echo "</td> <td>";
                          echo $show['favouritePlay'];
                          echo "</td> <td>";

                          /*this box checked if IsSponsored = 1*/
                          echo "<input type=\"radio\" name=\"".$show['ChildID']." \" value=\"1\" ".$sponsore d[$show['IsSponsored ']]."></input>Is sponsored";
                          echo "</td> <td>";

                          /*this box checked if IsSponsored = 0*/
                          echo "<input type=\"radio\" name=\"".$show['ChildID']." ''\" value=\"0\" ".$not_sponsore d[$show['IsSponsored ']]."></input>Is not sponsored";
                          echo "</td> <td>";
                          echo $show['dateOfBirth'];
                          echo "</td> </tr>";
                          }

                          echo "</table>";

                          ?>

                          </body>
                          </html>
                          [/php]

                          Comment

                          • lozwaldo
                            New Member
                            • Feb 2008
                            • 37

                            #14
                            Originally posted by hsriat
                            remove the space after IsSponsored (in line 83 and 87) and check its spelling against the one in the db.
                            removed space and works PERFECTLY in Firefox........ however get this error from IE6

                            Undefined index: countryName in C:\Inetpub\wwwr oot\practice\ch ildc.php on line 15 PHP
                            Undefined index: gender in C:\Inetpub\wwwr oot\practice\ch ildc.php on line 16 PHP
                            Undefined index: ChildID in C:\Inetpub\wwwr oot\practice\ch ildc.php on line 17

                            Comment

                            • Markus
                              Recognized Expert Expert
                              • Jun 2007
                              • 6092

                              #15
                              Originally posted by lozwaldo
                              removed space and works PERFECTLY in Firefox........ however get this error from IE6

                              Undefined index: countryName in C:\Inetpub\wwwr oot\practice\ch ildc.php on line 15 PHP
                              Undefined index: gender in C:\Inetpub\wwwr oot\practice\ch ildc.php on line 16 PHP
                              Undefined index: ChildID in C:\Inetpub\wwwr oot\practice\ch ildc.php on line 17
                              It wont be the browser as the errors are given from the server.

                              Place an @ symbol before the post:
                              [php]
                              $_something = @$_POST['something'];
                              [/php]
                              So, if the post isnt there, it won't throw an error.

                              Comment

                              Working...