Unable to catch dropdownlist value, error in SQL statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • valeberry
    New Member
    • May 2007
    • 7

    Unable to catch dropdownlist value, error in SQL statement

    [PHP]index
    <?php
    include ("conn.php") ;
    require_once("t abs.php");
    ?>
    <html>
    <head>
    <?php tabs_header(); ?>
    </head>
    <body>
    <div style="width:60 0px;">
    <?php tabs_start(); ?>
    <?php tab( "Junior Colleges" ); ?>
    <form id="form1" name="form1" method="post" action="dd2.php ">
    <?PHP
    $query = 'SELECT DISTINCT schName FROM schools';
    //$query2='SELECT DISTINCT schLocation FROM schools';
    $result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
    echo "<select name=select value='' ><option>Plea se select</option>";
    while($nt=mysql _fetch_array($r esult)){//Array or records stored in $nt
    echo "<option value=$nt[schName]>$nt[schName]</option>";
    /* Option values are added by looping through the array */
    }
    echo "</select>";// Closing of list box

    echo '<input type="submit" value="Yes" />';



    ?></form>
    <?php tab( "PolyTechni c" ); ?>
    This is the second tab.
    <?php tabs_end(); ?>
    </div>
    </body>
    </html>
    [/PHP]

    [PHP]Display result
    <?PHP
    include ("conn.php") ;
    ?>
    <?PHP
    $schName=$_Get['select'];

    $query = "SELECT schName FROM schools where schName='$schNa me'";

    $numresults = mysql_query($qu ery) or die ("<center>Could n't execute query</center>");
    $row= mysql_fetch_arr ay($numresults) ;
    echo $numresults;
    echo $row;
    print $schName;
    echo '<br>';

    echo "<center><h1>Se arch results for: " . $schName ." </h1></center>";


    ?>
    [/PHP]

    Error Message when supposed to display result:
    Couldn't execute query
    "); $row= mysql_fetch_arr ay($numresults) ; echo $numresults; echo $row; print $schName; echo '
    '; echo "
    Search results for: " . $schName ."
    "; ?>


    Any1 knows what is wrong with my statement??
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    [PHP]$schName=$_GET['select']; [/PHP]

    Comment

    • valeberry
      New Member
      • May 2007
      • 7

      #3
      Originally posted by ajaxrand
      [PHP]$schName=$_GET['select']; [/PHP]
      What shld i do to solve this error?
      Do i use $_Request to get the schName from drop downlist?

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Originally posted by valeberry
        What shld i do to solve this error?
        Do i use $_Request to get the schName from drop downlist?
        Ajaxrand was pointing out that it s/b $_GET instead of $_Get.

        At this line:

        [PHP]
        $numresults = mysql_query($qu ery) or die ("<center>Could n't execute query</center>");
        [/PHP]

        Try this instead:
        [PHP]
        $numresults = mysql_query($qu ery) or die (mysql_error()) ;
        [/PHP]

        Also, try running your query manually in MySQL. Make sure you're actually getting results.

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          [PHP]$_Get [/PHP]is wrong
          [PHP]$_GET[/PHP] is the correct way.

          Comment

          • ak1dnar
            Recognized Expert Top Contributor
            • Jan 2007
            • 1584

            #6
            pbmods has posted before me. Thanks.:)
            Valeberry did you solve the problem.

            Comment

            • valeberry
              New Member
              • May 2007
              • 7

              #7
              Originally posted by ajaxrand
              pbmods has posted before me. Thanks.:)
              Valeberry did you solve the problem.
              Yup. Thanks.
              However, I'm still unable to display full name of the school from drop dwnlist. I'm getting from the database.
              I hav insert the values.

              [PHP]dd1
              <?PHP
              $query = 'SELECT DISTINCT schName FROM schools';
              //$query2='SELECT DISTINCT schLocation FROM schools';
              $result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
              echo "<select name= 'select' value='' ><option>Plea se select</option>";
              while($nt=mysql _fetch_array($r esult))
              {
              //Array or records stored in $nt
              echo "<option value=$nt[schName]>$nt[schName]</option>";
              /* Option values are added by looping through the array */
              }
              echo "</select>";// Closing of list box

              echo '<input type="submit" value="Yes" />';



              ?>


              [/PHP]

              Is there anything wrong with the logic with the follwin statement?
              echo "<option value=$nt[schName]>$nt[schName]</option>";


              [PHP]dd2
              <?PHP
              include ("conn.php") ;
              ?>
              <?PHP
              $schName= $_GET['select'];
              echo $_REQUEST[$schName];
              $query = "SELECT schName FROM schools where schDesc='$schNa me'";

              $numresults = mysql_query($qu ery) or die ('Query failed: ' . mysql_error());
              $row= mysql_fetch_row ($numresults);
              $row[0] =$schName ;


              echo "<center><h1>Se arch results for: " . $schName ." </h1></center>";



              ?>

              [/PHP]

              From the following codes:
              $row= mysql_fetch_row ($numresults);
              $row[0] =$schName ;

              I can display Victoria instead of Victoria Junior College.

              How shld I resolve the problem to display Victoria Junior College instead of Victoria?

              Comment

              • ak1dnar
                Recognized Expert Top Contributor
                • Jan 2007
                • 1584

                #8
                You are still printing this variable
                [PHP] $schName= $_GET['select']; [/PHP]

                Not the Table value.Use like this.

                [PHP]<?PHP
                include ("conn.php") ;
                $schName= $_GET['select'];
                //echo $_REQUEST[$schName];
                $query = "SELECT schName FROM schools where schDesc='$schNa me'";
                $numresults = mysql_query($qu ery) or die ('Query failed: ' . mysql_error());
                $row= mysql_fetch_row ($numresults);
                //$row[0] =$schName ;
                echo "<center><h1>Se arch results for: " . $row[0] ." </h1></center>";
                ?> [/PHP]

                Comment

                • valeberry
                  New Member
                  • May 2007
                  • 7

                  #9
                  Originally posted by ajaxrand
                  You are still printing this variable
                  [PHP] $schName= $_GET['select']; [/PHP]

                  Not the Table value.Use like this.

                  [PHP]<?PHP
                  include ("conn.php") ;
                  $schName= $_GET['select'];
                  //echo $_REQUEST[$schName];
                  $query = "SELECT schName FROM schools where schDesc='$schNa me'";
                  $numresults = mysql_query($qu ery) or die ('Query failed: ' . mysql_error());
                  $row= mysql_fetch_row ($numresults);
                  //$row[0] =$schName ;
                  echo "<center><h1>Se arch results for: " . $row[0] ." </h1></center>";
                  ?> [/PHP]
                  It did nt display ath. =(
                  Output was a blank page.

                  Comment

                  • ak1dnar
                    Recognized Expert Top Contributor
                    • Jan 2007
                    • 1584

                    #10
                    Originally posted by valeberry
                    It did nt display ath. =(
                    Output was a blank page.
                    Is it working when you pass a value to $schName manually.

                    [PHP]<?PHP
                    include ("conn.php") ;
                    //$schName= $_GET['select'];
                    $schName= 'victoriya';
                    //echo $_REQUEST[$schName];
                    $query = "SELECT schName FROM schools where schDesc='$schNa me'";
                    $numresults = mysql_query($qu ery) or die ('Query failed: ' . mysql_error());
                    $row= mysql_fetch_row ($numresults);
                    //$row[0] =$schName ;
                    echo "<center><h1>Se arch results for: " . $row[0] ." </h1></center>";
                    ?>[/PHP]

                    Comment

                    Working...