???passing a query from a form???

From: Joe (t3463_at_hotmail.com)
Date: 03/29/04

  • Next message: Riddic: "Re: ???passing a query from a form???"
    Date: 28 Mar 2004 17:11:54 -0800
    
    

    I have wrote a script to query my mysql database based up a name that
    is selected from an HTML list menu, the form action calls to my php
    script from my html doc, I have tested connectivity to the databse and
    have added a manual sql query to my php script to be sure it is
    functioning properly, the problem is I'm not sure how to get the
    script to see what option the html form is sending, I thought I could
    use:

    $query = "SELECT * FROM table WHERE email =
    '{$_GET['selecteduser']}@mydomain.com'";

    but that doesn't seem to be working properly. Maybe the HTML document
    is sending it correctly? Here is my form:

    <form action="report_results.php" method="post">
    <select name="selecteduser">
    <option value="selecteduser">Select One:</option>
    <option value="user1@mydomain.com">user1</option>
    <option value="user2@mydomain.com">user2</option>
    </select>
    <input type="submit" name="submit" value="Go!">
    </form>

    This form calls to the php script which then takes the input from the
    HTML form and processes it into the $_GET query and sends it to the
    while loop in the script, I'm not sure why this is not working? Here
    is my php code:

    PHP:
    --------------------------------------------------------------------------------
     <?php
      $db = mysql_connect("localhost", "sqluser", "sqlpasswd") or
    die("Could not connect to Mysql");
       if (!$db == False)
       {
           mysql_select_db("mydb");
          $query = "SELECT * FROM table WHERE email =
    '{$_GET['selecteduser']}@mydomain.com'";

           $result = mysql_query($sql,$db);
           while ($row = mysql_fetch_row($result))
           {
               print "<tr>";
                     foreach ($row as $field)
                     {
                     print "<td>$field</td>";
                     }
               print "</tr>";
           }
           mysql_close($cn);
       }
       else
       {
           print "Problem Connecting to the Database<br>";
       }
    ?>
    --------------------------------------------------------------------------------

    Does anyone have any suggestions??

    Thanks


  • Next message: Riddic: "Re: ???passing a query from a form???"

    Relevant Pages

    • Re: how to run scripts after a page has already loaded and been sent to a users browser?
      ... > It's because PHP is a server side scripting language, ... > do stuff before you send stuff to user's web browser. ... As we've discussed on this newsgroup before, if a script starts ... that is after the last HTML is sent to a web browser. ...
      (alt.php)
    • Re: How do we get there from here?
      ... Unlike my dislike for PHP, my dislike for SQL is based on ... >>> up with at least html and php quite mixed into each other, ... Using a PHP script to send HTML ... code to a browser in no way taints that code. ...
      (comp.databases.pick)
    • Re: Form Data -> Variables or an Array?
      ... Forgive me I am a PHP newbie. ... I have a small script that enables me to ... I want to use the HTML formatted form ... variables or an array, so that I can call the data later in the same ...
      (comp.lang.php)
    • Cant make this page work
      ... I can't make this script work properly. ... The script at the bottom of the html page ... Does someone have a perl ... sub output_trace_headers { ...
      (comp.lang.javascript)
    • Re: Form Data -> Variables or an Array?
      ... Forgive me I am a PHP newbie. ... I have a small script that enables me to ... I want to use the HTML formatted form because ... variables or an array, so that I can call the data later in the same ...
      (comp.lang.php)