Jump to content

blackdogupya

Members
  • Posts

    35
  • Joined

  • Last visited

Everything posted by blackdogupya

  1. Hey Guys, Struggling again with some full text searching etc. I have a MySQL statement in my code but it's not working. Now, it's probably something extremely simple, but I just can't see it. //Now we search for our search term, in the field the user specified so we know how many pages to link to at the bottom $data = mysql_query("SELECT * , MATCH ('status', 'date', 'species', 'breed', 'sex', 'primary_colour', 'colour', 'distinctive_traits', 'fur_length', 'age', 'desexed', 'microchipped', 'suburb', 'pound_area', 'contact', 'link') AGAINST ('%$find%') AS score FROM animal_info WHERE MATCH ('status', 'date', 'species', 'breed', 'sex', 'primary_colour', 'colour', 'distinctive_traits', 'fur_length', 'age', 'desexed', 'microchipped', 'suburb', 'pound_area', 'contact', 'link') AGAINST ('%$find%') $max"); //Make sure we have some results to pass $result = mysql_query($data) or die("No Results Here"); //And we display the results of the search query as long as there is some while($row = mysql_fetch_array($result)) { //Build the HTML for the results in the table Now, my second question is that I've made a quick template for this, but I'm not sure how to format the "or die()" statement so it looks pretty with the header, footer etc. $result = mysql_query($data) or die("**SOME HTML FORMATTING IN HERE**"); Any help, once again, would be greatly appreciated! Cheers, Dave
  2. ^^^ Does your form have a field named 'searching', with a value of 'yes'? Is your form method set to post? Have you set the error_reporting and display_errors settings to the suggested values (and confirmed that they actually changed to those values after you restarted your web server)? Well, I have a little egg on my face here! :S I was uploading the modified file to the wrong directory!!! It's working! Needs a little refining for the results to display in a good way, but I can sort that! Thank you all so much! It's great to have a resource like this to help, and you guys are all amazing for putting in your free time to help idiots like me! Thanks again! Cheers, Dave
  3. Good idea, but to no avail! :'(
  4. Okay, I've changed everything you have all suggested, here's the code as it stands now: <? //Here we display stuff if they have submitted the form if ( $_POST['searching'] == 'yes' ) { echo "<h2>Results</h2><p>"; //If they stuffed up and didn't search for anything, we show them this if ($find == "") { echo "<p>Oh, Bianca, you need to enter SOMETHING to search!"; exit; } //If everything is all good, we connect to the database mysql_connect("localhost", "******", "******") or die(mysql_error()); mysql_select_db("******") or die(mysql_error()); //Let's not forget the register globals off crap $status = $_POST['status']; $date = $_POST['date']; $species = $_POST['species']; $breed = $_POST['breed']; $sex = $_POST['sex']; $primary_colour = $_POST['primary_colour']; $colour = $_POST['colour']; $distinctive_traits = $_POST['distinctive_traits']; $fur_length = $_POST['fur_length']; $age = $_POST['age']; $desexed = $_POST['desexed']; $microchipped = $_POST['microchipped']; $suburb = $_POST['suburb']; $pound_area = $_POST['pound_area']; $contact = $_POST['contact']; $link = $_POST['link']; $columns = $_POST['columns']; $find = $_POST['find']; // We perform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $data = mysql_query("SELECT * FROM animal_info WHERE upper($columns) LIKE'%$find%'"); //And we display the results while($row = mysql_fetch_array( $data )) { echo "<table>"; echo "<tr>"; echo "<td>".$row['status']."</td>"; echo "<td>".$row['date']."</td>"; echo "<td>".$row['species']."</td>"; echo "<td>".$row['breed']."</td>"; echo "<td>".$row['sex']."</td>"; echo "<td>".$row['primary_colour']."</td>"; echo "<td>".$row['colour']."</td>"; echo "<td>".$row['distinctive_traits']."</td>"; echo "<td>".$row['fur_length']."</td>"; echo "<td>".$row['age']."</td>"; echo "<td>".$row['desexed']."</td>"; echo "<td>".$row['microchipped']."</td>"; echo "<td>".$row['suburb']."</td>"; echo "<td>".$row['pound_area']."</td>"; echo "<td>".$row['contact']."</td>"; echo "<td>".$row['link']."</td>"; echo "</tr>"; echo "</table>"; } //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 "Nope, couldn't find anything here! Maybe refine your search criteria?<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> " .$find; } ?> Still giving me a blank page. When I view source, that's blank also! My eyes are going blurry with looking at it so hard! Any other ideas. Thanks again for your help! Cheers, Dave
  5. I've actually declared the $_POST['find'] in the list after posting this, so that's now there. I've added the error reporting, but again, nothing is showing up. No errors. This is starting to give me the s*its! Thanks for your help so far!
  6. Thanks for the reply! I've made the change as suggested, but it's still just returning a blank page. Cheers, Dave
  7. Okay, after successfully getting a form to input data to a MySQL database, I'm now trying to get the data back out by searching. Search form code: <form name="search" method="post" action="process_search.php"> Seach for: <input type="text" name="find" /> in <select name="columns"> <option value="">Please choose one:</option> <option value="status">Status</option> <option value="date">Date</option> <option value="species">Species</option> <option value="breed">Breed</option> <option value="sex">Sex</option> <option value="primary_colour">Primary Colour</option> <option value="colour">Colour</option> <option value="distinctive_traits">Distinctive Traits</option> <option value="fur_length">Fur Length</option> <option value="age">Age</option> <option value="desexed">Desexed</option> <option value="microchipped">Microchipped</option> <option value="suburb">Suburb</option> <option value="pound_area">Pound Area</option> <option value="contact">Contact</option> <option value="link">Link</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> All good there! Form displays how I want it to, and submits correctly. The bit I'm struggling with is the process_search.php side of things. This is what I have (note that i'm trying to get the results into a formatted table and I'd like more results if the match is in more than one column): <? //Here we display stuff if they have submitted the form if ($searching =="yes") { echo "<h2>Results</h2><p>"; //If they stuffed up and didn't search for anything, we show them this if ($find == "") { echo "<p>Oh, Bianca, you need to enter SOMETHING to search!"; exit; } //If everything is all good, we connect to the database mysql_connect("localhost", "******", "******") or die(mysql_error()); mysql_select_db("******") or die(mysql_error()); //Let's not forget the register globals off crap $status = $_POST['status']; $date = $_POST['date']; $species = $_POST['species']; $breed = $_POST['breed']; $sex = $_POST['sex']; $primary_colour = $_POST['primary_colour']; $colour = $_POST['colour']; $distinctive_traits = $_POST['distinctive_traits']; $fur_length = $_POST['fur_length']; $age = $_POST['age']; $desexed = $_POST['desexed']; $microchipped = $_POST['microchipped']; $suburb = $_POST['suburb']; $pound_area = $_POST['pound_area']; $contact = $_POST['contact']; $link = $_POST['link']; $columns = $_POST['columns']; // We perform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $data = mysql_query("SELECT * FROM animal_info WHERE upper($columns) LIKE'%$find%'"); //And we display the results where($result = mysql_fetch_array( $data )) { echo "<tr>"; echo "<td>".$row['status']."</td>"; echo "<td>".$row['date']."</td>"; echo "<td>".$row['species']."</td>"; echo "<td>".$row['breed']."</td>"; echo "<td>".$row['sex']."</td>"; echo "<td>".$row['primary_colour']."</td>"; echo "<td>".$row['colour']."</td>"; echo "<td>".$row['distinctive_traits']."</td>"; echo "<td>".$row['fur_length']."</td>"; echo "<td>".$row['age']."</td>"; echo "<td>".$row['desexed']."</td>"; echo "<td>".$row['microchipped']."</td>"; echo "<td>".$row['suburb']."</td>"; echo "<td>".$row['pound_area']."</td>"; echo "<td>".$row['contact']."</td>"; echo "<td>".$row['link']."</td>"; echo "</tr>"; } else { echo "ERROR: ".mysql_error(); } //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 "Nope, couldn't find anything here! Maybe refine your search criteria?<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> " .$find; } ?> Trouble with this is that I'm not getting any errors OR results! ANY help would be appreciated HUGELY! Cheers, Dave
  8. I just changed the MySQL field to text and let it populate. There's no real reason for it to be a DATE field. Thanks for the suggestions though! Cheers, Dave
  9. He is referencing the input field by it's class, which is fine. What format is the date being passed in? To be inserted into a DATE field, it needs to be YYYY-MM-DD I changed the code to this, as suggested by the jQuery peeps: <script type="text/javascript" charset="utf-8"> $(function() { $('.date-pick').datePicker( "option", "dateFormat", "yyyy-mm-dd").dpSetSelected(new Date().asString()); }); </script> But I might be barking up the wrong tree. Cheers, Dave
  10. Hey Guys and Girls! I'm a bit of a noob when it comes to PHP and MySQL, so I'm hoping you can help me! I'm trying to create a form and parse the data to an MySQL database. The form code I have is as follows: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- jQuery --> <script type="text/javascript" src="js/jquery.js"></script> <!-- required plugins --> <script type="text/javascript" src="js/date.js"></script> <!--[if IE]><script type="text/javascript" src="scripts/jquery.bgiframe.min.js"></script><![endif]--> <!-- jquery.datePicker.js --> <script type="text/javascript" src="js/date_picker.js"></script> <!-- datePicker required styles --> <link rel="stylesheet" type="text/css" media="screen" href="css/default.css"> <script type="text/javascript" charset="utf-8"> $(function() { $('.date-pick').datePicker().dpSetSelected(new Date().asString()); }); </script> <title>POPLAF Database - Add Animal</title> </head> <body> <form method="post" action="process.php"> Status:<br> <BR /> <input type="radio" name="status" value="lost" /> Lost<br /><BR /> <input type="radio" name="status" value="found" /> Found <BR /> <BR /> Date: <br> <input name="date" id="date" class="date-pick" /> <br><br> <input type="submit" name="Submit" value="Submit"> </form> </body> </html> This part is fine. Here's the process.php code: <? // Database Connection. Change if required. $dbms = 'mysqli'; $hostname = 'localhost'; $db_user = '*******'; $database = '*******'; $db_password = '*******'; $load_extensions = ''; $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db($database,$db); if ($_SERVER['REQUEST_METHOD'] == "POST") { // the following 4 lines are needed if your server has register_globals set to Off $status = $_POST['status']; $date = $_POST['date']; $sql = "INSERT INTO animal_info (status, date) VALUES ('$status','$date')"; //declare in the order variable $result = mysql_query($sql); //order executes if($result){ echo("<br>Input data is succeed"); } else{ echo "ERROR: ".mysql_error(); } ?> <? } ?> This part also works okay! My trouble is, with getting the date correct! Whenever I submit the form, the database shows the date as 0000-00-00 and not the date entered. I'm using jQuery for the calendar and date. Any help would be appreciated! Cheers, Dave
×
×
  • 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.