<form action="search.php" method="post"> <br> Seeking: <select size="1" name="gender" id="gender"> <option value="males" selected>Males</option> <option value="females">Females</option> </select> Between the ages of: <select name="age_first" id="age_first"> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">32</option> <option value="33">33</option> <option value="34">34</option> <option value="35">35</option> <option value="36">36</option> <option value="37">37</option> <option value="38">38</option> <option value="39">39</option> <option value="40">40</option> <option value="41">41</option> <option value="42">42</option> <option value="43">43</option> <option value="44">44</option> <option value="45">45</option> <option value="46">46</option> <option value="47">47</option> <option value="48">48</option> <option value="49">49</option> <option value="50">50</option> </select> and <select name="age_second" id="age_second"> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24" selected="selected">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">32</option> <option value="33">33</option> <option value="34">34</option> <option value="35">35</option> <option value="36">36</option> <option value="37">37</option> <option value="38">38</option> <option value="39">39</option> <option value="40">40</option> <option value="41">41</option> <option value="42">42</option> <option value="43">43</option> <option value="44">44</option> <option value="45">45</option> <option value="46">46</option> <option value="47">47</option> <option value="48">48</option> <option value="49">49</option> <option value="50">50</option> </select> Near: <input name="zip" type="text" id="zip" size="15" maxlength="10"> <input type="Submit" value="Submit" name="Submit"> </form>
3 replies to this topic
#1
Posted 14 April 2011 - 03:47 PM
I have a form that lets users search members based on gender, age and zipcode but I'm not sure how to go about retrieving the data from my database. Any help would be greatly appreciated. Here's my form:
|
|
|
#2
Posted 14 April 2011 - 04:16 PM
Your form would generate the following values inside the $_POST in search.php array:
You should properly verify your data before you work in the database with it, such as checking if all the forms are filled out such as using isset(), and as well verify if those sets of data are in valid form (i.e. zip contains only numbers, and is five in length)
You can then form a query once all data members are safe,
Array
(
[gender] => males
[age_first] => 18
[age_second] => 24
[zip] =>somezipcode
[Submit] => Submit
)For example, you would access their zip code through $_POST['zip'].You should properly verify your data before you work in the database with it, such as checking if all the forms are filled out such as using isset(), and as well verify if those sets of data are in valid form (i.e. zip contains only numbers, and is five in length)
You can then form a query once all data members are safe,
$sql = "SELECT id, otherdataFROM table WHERE gender = '$gender' AND age BETWEEN $age_first AND $age_second AND (etc.)";
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 14 April 2011 - 05:07 PM
I understand the sql part but I'm not sure what you mean with the arrays.
#4
Posted 14 April 2011 - 06:05 PM
You may benefit from a tutorial on how to access form data in PHP
PHP form tutorial
On your form you have set the data to be sent using the POST method, so PHP will take this data and place it in to an array. This array will be named $_POST.
If you have name="someform" on your HTML form, then it will become $_POST['someform'] in the PHP script for ease of access.
If you are unclear of any thing feel free to ask!
PHP form tutorial
On your form you have set the data to be sent using the POST method, so PHP will take this data and place it in to an array. This array will be named $_POST.
If you have name="someform" on your HTML form, then it will become $_POST['someform'] in the PHP script for ease of access.
If you are unclear of any thing feel free to ask!
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









