PHPnewby! Posted February 25, 2007 Share Posted February 25, 2007 Hi guys, I'm having problems getting my search form to do anything! Any help would be GREATLY appreciated...think its more a problem with the PHP than SQL? Thanks. <form name="search" method="post" action="<?=$PHP_SELF?>"> <table width="100%" border="0"> <tr> <td width="26%">Gender</td> <td width="27%"><select name="Gender" id="Gender"> <option>Female</option> <option>Male</option> </select> </td> <td width="21%"> </td> <td width="26%"> </td> </tr> <tr> <td>Interests</td> <td><input name="Interests" type="text" id="Interests" /></td> <td> </td> <td> </td> </tr> <tr> <td>Year of Birth from:</td> <td><input name="DOB_from" type="text" id="DOB_from" /></td> <td>Year of Birth to: </td> <td><input name="DOB_to" type="text" id="DOB_to" /></td> </tr> <tr> <td>Travel Aspirations</td> <td><input name="TravelAspirations" type="text" id="TravelAspirations" /></td> <td> </td> <td> </td> </tr> <tr> <td>Message </td> <td><input name="Message" type="text" id="Message" /></td> <td> </td> <td> </td> </tr> </table> <p> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </p> </form> <?php //Now we search for our search term, in the field the user specified $Gender = $_POST['Gender']; $Interests = $_POST['Interests']; $DOB_from = $_POST['DOB_from']; $DOB_to = $_POST['DOB_to']; $TravelAspirations = $_POST['TravelAspirations']; $Message = addslashes($_POST['Message']); //This is only displayed if they have submitted the form if ($_POST['searching']=="yes") { echo "<h2>Members who met your search criteria</h2><p>"; //If they did not enter a search term we give them an error if ($Gender AND $Interests AND $Message AND $DOB_from AND $DOB_to AND $TravelAspirations = "") { echo "<p>You forgot to enter a search term"; exit; } $data = mysql_query("SELECT * FROM Members WHERE (Gender = '$Gender') OR (Interests LIKE '%$Interests%') OR (DOB BETWEEN '$DOB_from' AND '$DOB_to') OR (TravelAspirations LIKE '%$TravelAspirations%') OR (Message LIKE '%$Message%')"); //And we display the results while($result = mysql_fetch_array( $data )) { echo $result['Gender']; echo "<br>"; echo $result['DOB']; echo "<br>"; echo $result['Interests']; echo "<br>"; echo $result['Interests']; echo "<br>"; echo $result['TravelAspirations']; echo "<br>"; echo $result['Message']; echo "<br>"; echo "<br>"; } $name = $result['username']; $email = $result['email']; echo "<a href='mailto:".$email. "'>".$name."</a>"; //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> "; } ?> Quote Link to comment Share on other sites More sharing options...
simcoweb Posted February 25, 2007 Share Posted February 25, 2007 Are you getting any type of error? Quote Link to comment Share on other sites More sharing options...
PHPnewby! Posted February 25, 2007 Author Share Posted February 25, 2007 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /export2/webroot/users/c3031698/ContactMembers.php on line 211 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /export2/webroot/users/c3031698/ContactMembers.php on line 234 It did once show a response when I selected a gender...but it showed both genders....and the response although I haven't changed anything is never to be seen again! :S Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 25, 2007 Share Posted February 25, 2007 Just glancing at it I found this error: if ($Gender AND $Interests AND $Message AND $DOB_from AND $DOB_to AND $TravelAspirations = "") Should be: if ($Gender == "" AND $Interests == "" AND $Message == "" AND $DOB_from = "" AND $DOB_to == "" AND $TravelAspirations == "") Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /export2/webroot/users/c3031698/ContactMembers.php on line 211 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /export2/webroot/users/c3031698/ContactMembers.php on line 234 Something is wrong with your queires Quote Link to comment Share on other sites More sharing options...
PHPnewby! Posted February 25, 2007 Author Share Posted February 25, 2007 I know, but I can't work out what Quote Link to comment Share on other sites More sharing options...
PHPnewby! Posted February 26, 2007 Author Share Posted February 26, 2007 Can anyone else help??? I'm really stuck and deadline is drawing closer and closer Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 26, 2007 Share Posted February 26, 2007 After every mysql_query() add an or die() $result = mysql_query($sql) OR die('sql: '.$sql.' - Error: '.mysql_error()); Quote Link to comment Share on other sites More sharing options...
craygo Posted February 26, 2007 Share Posted February 26, 2007 try and get an error message from mysql $sql = "SELECT * FROM Members WHERE (Gender = '$Gender') OR (Interests LIKE '%$Interests%') OR (DOB BETWEEN '$DOB_from' AND '$DOB_to') OR (TravelAspirations LIKE '%$TravelAspirations%') OR (Message LIKE '%$Message%')"; mysql_query($sql) or die(mysql_error()); Ray Quote Link to comment Share on other sites More sharing options...
PHPnewby! Posted February 26, 2007 Author Share Posted February 26, 2007 Thanks Ray, I've done what you said.....it now states "No Database Selected" with no error messages...and it doesn't matter whether I have selected anything within the search form or not! I tried re-stating the connect to database line within this section of php, but no change! Any other ideas? sorry! Thanks. Quote Link to comment Share on other sites More sharing options...
craygo Posted February 26, 2007 Share Posted February 26, 2007 well you need to connect to your database. try this at the top. <?php // database settings $dbhost = 'localhost'; // database server $dbuser = 'username'; // db username $dbpass = 'password'; // db password $dbname = 'mydb'; // db name // connect to database $mysql_conn = @mysql_connect($dbhost, $dbuser, $dbpass) or die("Could not connect to Mysql, Please check settings and try again"); @mysql_select_db($dbname, $mysql_conn) or die("DataBase does not exist"); ?> Ray Quote Link to comment Share on other sites More sharing options...
PHPnewby! Posted February 26, 2007 Author Share Posted February 26, 2007 I've got "require_once('Connections/TCO.php');" at the top of the page. :S Quote Link to comment Share on other sites More sharing options...
craygo Posted February 26, 2007 Share Posted February 26, 2007 well post that code, because that seems to be the problem if you cannot connect to the database. Ray Quote Link to comment Share on other sites More sharing options...
PHPnewby! Posted February 26, 2007 Author Share Posted February 26, 2007 <?php session_start(); $User = $_SESSION['MM_Username']; if (!$User) { header("Location: memberfeatures.php"); } require_once('Connections/TCO.php'); ?> I don't see the problem with this section, as I have this for several of my pages and it successfully connects. :S Is it something to do with the variable $data? I can't see where this is defined? (adapted code from elsewhere you see!). Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 you need to check the connection with the database whether its getting connected to the database or not... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.