Jump to content

Search form not working


drayarms

Recommended Posts

I wrote the search form below to enable users search other users of a site based on certain criteria like age, race etc.  Then I wrote the php script beneath, to execute that search.  I decided to make the script very simple, searching only for one criterion for now (ethnicity).  So even though I have several fields in the search form, I wrote the script to process only one of those fields(ethnicity).  So basically, the script searches all records for members on the site from two tables called images and members(the members table has an "ethnicity column"), who meet the user's ethnicity preference and returns certain columns for all members who meet that preference.  Well when  I click the submit button, all I get is "Form not submitted".  I added that form not submitted clause at the end of the script just after I had tweaked the script in every way possible but got nothing but a blank page every time I submitted the form.  So take a look people and tell me what could be going wrong here.  Appreciate any help.


<form id="search_profiles_form" action= "profile_search.php">





						Seeking A:  
						<select name= "sex">
							<option value= "man">Man</option>
							<option value= "woman">Woman</option>
							<option value= "both">Both</option>
						<select>   


						<p> <tab> Age Range: 
						<?php
						print '<select name= "min_age">';
						for ($age = 18; $age <= 99; $age++) {
						    print "\n<option value=\"$age\">$age</option>";
						}
						print '</select>'; ?> </tab>

						<tab> and: <?php
						print '<select name= "max_age">';
						for ($age = 18; $age <= 99; $age++) {
						    print "\n<option value=\"$age\">$age</option>";
						}
						print '</select>'; ?> </tab> </p>


						<p>Distance:     <select name= "distance">
							<option name="5">Within 5 Miles</option>
							<option name="10">Within 10 Miles</option>
							<option name="50">Within 50 Miles</option>
							<option name="100">Within 100 Miles</option>
							<option name="250">Within 250 Miles</option>
							<option name="any">Beyond 250 Miles</option>
						</select> </p>



						<p>Ethnicity:     <select name= "ethnicity">
							<option name="black">Black/African Descent</option>
							<option name="white">Caucasian?European Descent</option>
							<option name="latino">Hispanic Non White</option>
							<option name="asian">Asian Descent</option>
							<option name="native_american">Native American</option>
							<option name="pacific_islander">Pacific Islander</option>
							<option name="indian">Indian Descent</option>
							<option name="middle_east">Middle Eastern</option>
							<option name="other">Other</option>
						</select> </p>


						<p>Last Active: <select name= "last_active">
							<option name="0">Online Now</option>
							<option name="1">1 Hr Ago</option>
							<option name="5">5 Hrs Ago</option>
							<option name="24">24 Hrs Ago</option>
							<option name="1wk">1 Week Ago</option>
							<option name="3wk">Over 3 Weeks Ago</option>
						</select> </p>


						<input type="hidden" name="submitted" value="TRUE"/>


						<p>          
						               
						<input type ="submit"  value="Search!"/> </p>







					</form>

 

And here goes the php script.


<?php

//address error handling

ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);


//authenticate user
require('auth.php');


if (isset($_POST['submitted'])) {

// Connect to the database.

        require_once ('config.php');

//Query the database.

$sql = "SELECT * FROM members INNER JOIN images ON members.member_id = images_member_id WHERE members.ethnicity = '{$_POST['ethnicity']}' AND images.cartegory = 'main' ";



$query = mysql_query($sql);



//Check for success here.

if(!$query)

{

    		trigger_error("SQL query $sql failed: " . mysql_error(), E_ERROR);

    		// Handle as desired

}else{  //If query is valid.

    		if(mysql_num_rows($query) > 0){


       			 while ($row = mysql_fetch_assoc($query)){ 

            		//Redirect to search results page.

		echo $_POST['ethnicity']; echo $row['member_id']; echo $_SESSION['id']; echo $row['image'];
         
		 }

        		 

   		 }else {//No rows returned.

        
        		echo 'No results match this search query.' ;

    			}

}//End of else if query is valid.

}else{ echo "form not submitted";}




?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.