taichi56 Posted June 14, 2013 Share Posted June 14, 2013 I recieved this coding on another site and changed it a little to get it to work with MYSQL database. I am able to connect to my localhost database but when I put in a search term I get this error: ! ) Notice: Undefined variable: Get in C:\wamp\www\search.php on line 15 Call Stack # Time Memory Function Location 1 0.0003 373624 {main}( ) ..\search.php:0 minimum length is 3 The error is showing on line 15: $query = $_GET['query'] Here is my code: <?php mysql_connect("localhost", "root", "") or die("Error connecting to the database: ".mysql_error()); mysql_select_db("magicgathering") or die(mysql_error()); ?> <!DOCTYPE html Public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR.xhtml/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Search Results</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <?php $query = $_Get['query']; //Gets value sent over search form $min_length = 3; //you can set minimum length of the query if you want if(strlen($query) >= $min_length){ // if query length is more or equal. $query = htmlspecialchars($query); // Changes characters used in html to their equivalents, for example: < to ≫ $query = mysql_real_escape_string($query); // makes sure nobody uses SQL injection $raw_results = mysql_query("SELECT * FROM tblmtg WHERE ('name' LIKE '%".$query."%') OR ('type' LIKE '%".$query."%')") or die(mysql_error()); //* means that it selects all fields, you can also write: 'id', 'name', 'type' // tblmtg is the name of our table // '%$query' is what we're looking for , % means anything, for example if $query is Hello 'name'='$query' // or if you want to match just full word so "gogohello" is out use '% $query %' ...OR... '$query %' ...OR... '% $query' if(mysql_num_rows($raw_results) > 0) { // if one or more rows are returned do following while($results = mysql_fetch_array($raw_results)) { // results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop echo "<p><h3>".$results['name']. "</h3>".$results['type']."</p>"; // posts results gotten from database (name and type) you can also show id ($results['id']) } } else { // if there is no matchig rows do the following echo "No results"; } } else { // if query length is less than minimum echo "minimum length is ".$min_length; } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
requinix Posted June 14, 2013 Share Posted June 14, 2013 The error is showing on line 15: $query = $_GET['query']Actually line 15 is $query = $_Get['query']; That difference matters. Quote Link to comment Share on other sites More sharing options...
taichi56 Posted June 14, 2013 Author Share Posted June 14, 2013 Actually line 15 is $query = $_Get['query']; That difference matters. Not sure what you are saying. Sorry. I am a newbie. Quote Link to comment Share on other sites More sharing options...
davidannis Posted June 14, 2013 Share Posted June 14, 2013 Capitalization Quote Link to comment Share on other sites More sharing options...
Solution taichi56 Posted June 14, 2013 Author Solution Share Posted June 14, 2013 Oh, so simple. Thank you to both of you. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 14, 2013 Share Posted June 14, 2013 You actually have a field in your html form named "query"? 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.