views:

75

answers:

4

So I have a form for people to fill out, which is below... Once they fill that form out, how can I query it and return the information from my database?

<form name="form" method="get" action="agents.php"> 
<table>
           <tr>
           <td width = "20%">Last Name: </td>
           <td><input type="text" name="LASTNAME" size="20"/> </td>
           </tr>
           <tr>
           <td width = "20%">City: </td>
           <td><input type="text" name="CITY" size="20"/> </td>
           </tr>
           <tr>
           <td>State: </td>
           <td><select name="state" size="1">

    <option value="AK">AK</option>
    <option value="AL">AL</option>
    <option value="AR">AR</option>
    <option value="AZ">AZ</option>
    <option value="CA">CA</option>
    <option value="CO">CO</option>
    <option value="CT">CT</option>
    <option value="DC">DC</option>
    <option value="DE">DE</option>
    <option value="FL">FL</option>
    <option value="GA">GA</option>
    <option value="HI">HI</option>
    <option value="IA">IA</option>
    <option value="ID">ID</option>
    <option value="IL">IL</option>
    <option value="IN">IN</option>
    <option value="KS">KS</option>
    <option value="KY">KY</option>
    <option value="LA">LA</option>
    <option value="MA">MA</option>
    <option value="MD">MD</option>
    <option value="ME">ME</option>
    <option value="MI">MI</option>
    <option value="MN">MN</option>
    <option value="MO">MO</option>
    <option value="MS">MS</option>
    <option value="MT">MT</option>
    <option value="NC">NC</option>
    <option value="ND">ND</option>
    <option value="NE">NE</option>
    <option value="NH">NH</option>
    <option value="NJ">NJ</option>
    <option value="NM">NM</option>
    <option value="NV">NV</option>
    <option value="NY">NY</option>
    <option value="OH">OH</option>
    <option value="OK">OK</option>
    <option value="OR">OR</option>
    <option value="PA">PA</option>
    <option value="RI">RI</option>
    <option value="SC">SC</option>
    <option value="SD">SD</option>
    <option value="TN">TN</option>
    <option value="TX">TX</option>
    <option value="UT">UT</option>
    <option value="VA">VA</option>
    <option value="VT">VT</option>
    <option value="WA">WA</option>
    <option value="WI">WI</option>
    <option value="WV">WV</option>
    <option value="WY">WY</option>
</select><br><br></td>
           </tr>
           <tr>
           <td>Zip: </td>
           <td><input type="text" name="ZIP" size="30"/> </td>
           </tr>

           </table>

<br> <br>
<input type="submit" name="Submit" value="Submit"> 
</form>
+2  A: 

As your form is in GET (see the method parameter), and sends data to agent.php (see the action attribute), agent.php will receive the data entered by the user, in the $_GET superglobal variable -- which is an array.

There will be one entry in that array for each field of the form ; and the key for each value will be the name attribute of the corresponding field.

Which means the $_GET array will contain something like this, for instance :

array
  'LASTNAME' => string 'my last name' (length=12)
  'CITY' => string 'my city' (length=7)
  'state' => string 'DE' (length=2)
  'ZIP' => string '12345' (length=5)
  'Submit' => string 'Submit' (length=6)

(I got this output using var_dump, with Xdebug installed)


To store those data to a database, you'll have to use mysqli_* functions, or PDO.

Pascal MARTIN
there should be also a name for each option so get can return them also
streetparade
@streetparade > I am not sure about that : without any "name" attribute on the "option" tags, I received the city I selected ;; And, judging from the HTML 4.01 specification, the "option" tag doesn't accept any "name" attribute : http://www.w3.org/TR/html4/interact/forms.html#edef-OPTION
Pascal MARTIN
The appropriate place for the name attribute is in the Select tag as in the original question, not in the option tag.
Zak
+1  A: 

You should really study PHP and MySql interaction for a while, at least the bases. Any answer given here (assuming someone understands the question) will only fix the single problem and move your "I'm stuck" point one step further.

kemp
+2  A: 

What you're asking for is too large a question for a site like this. I suggest you check out some tutorials online about PHP and MySQL (or whatever your database is) for beginners. There are lots of good ones out there. Read two or three and when you get stuck with a specific problem, then post a new question here.

Scott Saunders
A: 

I think you should follow the tutorial here: http://www.freewebmasterhelp.com/tutorials/phpmysql it will walk you through step by step how to do this.

Zak