Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 26th, 2008, 3:13 PM   #11
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
Re: Simple PHP Search Script

Okay, done.
Now I get this error:
SELECT * FROM users WHERE info LIKE '%HELLO%'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIKE '%HELLO%'' at line 1

With this code:

php Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>arnack.com Gaming Wesbite Database</title>
  4. </head>
  5. <body>
  6. <h2>Search</h2>
  7. <form name="search" method="post" action="<?=$PHP_SELF?>">
  8. Seach for: <input type="text" name="find" /> in
  9. <Select NAME="field">
  10. <Option VALUE="fname">First Person Shooters</option>
  11. <Option VALUE="lname">Role PLaying Games</option>
  12.  
  13. <Option VALUE="info">Real Time Strategy</option>
  14. </Select>
  15. <input type="hidden" name="searching" value="yes" />
  16. <input type="submit" name="search" value="Search" />
  17. </form>
  18. <?
  19. $searching = $_POST['searching'];
  20. $find = $_POST['find'];
  21. //This is only displayed if they have submitted the form
  22. if ($searching =="yes")
  23. {
  24. echo "<h2>Results</h2><p>";
  25.  
  26. //If they did not enter a search term we give them an error
  27. if ($find == "")
  28. {
  29. echo "<p>You forgot to enter a search term";
  30. exit;
  31. }
  32.  
  33. // Otherwise we connect to our Database
  34. mysql_connect("localhost", "arnackco_Arnack", "oompa123") or die(mysql_error());
  35. mysql_select_db("arnackco_search") or die(mysql_error());
  36.  
  37. // We preform a bit of filtering
  38. $find = strtoupper($find);
  39. $find = strip_tags($find);
  40. $find = trim ($find);
  41.  
  42.  
  43. //Now we search for our search term, in the field the user specified
  44.  
  45. $sql = "SELECT * FROM users WHERE info LIKE '%$find%'";
  46.  
  47. echo $sql;
  48.  
  49. $data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE '%$find%'") or die(mysql_error());
  50.  
  51. //And we display the results
  52. while($result = mysql_fetch_array( $data ))
  53. {
  54. echo $result['fname'];
  55. echo " ";
  56. echo $result['lname'];
  57. echo "<br>";
  58. echo $result['info'];
  59. echo "<br>";
  60. echo "<br>";
  61. }
  62.  
  63. //This counts the number or results - and if there wasn't any it gives them a little message explaining that
  64. $anymatches=mysql_num_rows($data);
  65. if ($anymatches == 0)
  66. {
  67. echo "Sorry, but we can not find an entry to match your query<br><br>";
  68. }
  69.  
  70. //And we remind them what they searched for
  71. echo "<b>Searched For:</b> " .$find;
  72. }
  73. ?>
  74. </body>
  75. </html>

this is the code in the mysql database
mysql Syntax (Toggle Plain Text)
  1. CREATE TABLE users (fname VARCHAR(30), lname VARCHAR(30), info BLOB);
  2.  
  3. INSERT INTO users VALUES ( "Jim", "Jones", "In his spare time Jim enjoys biking, eating pizza, and classical music" ), ( "Peggy", "Smith", "Peggy is a water sports enthusiast who also enjoys making soap and selling cheese" ),( "Maggie", "Martin", "Maggie loves to cook itallian food including spagetti and pizza" ),( "Tex", "Moncom", "Tex is the owner and operator of The Pizza Palace, a local hang out joint" )
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.
Arnack is offline   Reply With Quote
Old Mar 26th, 2008, 3:31 PM   #12
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,623
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
Re: Simple PHP Search Script

Look at line 49 of the code that you just posted.
Looks like this:
php Syntax (Toggle Plain Text)
  1. $data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE '%$find%'") or die(mysql_error());
should be:
php Syntax (Toggle Plain Text)
  1. $data = mysql_query($sql) or die(mysql_error());

Right now you aren't using the $sql variable that you used to change the sql statement.
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is offline   Reply With Quote
Old Mar 26th, 2008, 3:50 PM   #13
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
Re: Simple PHP Search Script

Ahh okay, I got it now. No errors anymore- now just this:

SELECT * FROM users WHERE info LIKE '%PEGGY%'Sorry, but we can not find an entry to match your query

So peggy which is in the database isn't even showing up x_x
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.
Arnack is offline   Reply With Quote
Old Mar 26th, 2008, 4:06 PM   #14
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,623
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
Re: Simple PHP Search Script

I don't know for sure but my guess is that the problem probably has something to do with the info column being a blob. Might want to change that to TEXT or read through MySQL's documention about the blob type and see if there is a way to look through it using like. Not sure how that data type really works. Maybe someone else can recommend something.

http://dev.mysql.com/doc/refman/5.0/en/blob.html

BLOB is for Binary objects so I would recommend changing that column to text.
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is offline   Reply With Quote
Old Mar 26th, 2008, 4:14 PM   #15
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
Re: Simple PHP Search Script

SWEET
Now a simple problem here:
What it does is this:
SELECT * FROM users WHERE info LIKE '%JIM%'Jim Jones
In his spare time Jim enjoys biking, eating pizza, and classical music

That's what it echoes. I need to get rid of the beginning part, of course. The code is found on this line:
$sql = "SELECT * FROM users WHERE info LIKE '%$find%'";
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.
Arnack is offline   Reply With Quote
Old Mar 26th, 2008, 4:26 PM   #16
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: Simple PHP Search Script

Well obviously don't echo $sql. Did you not write this script yourself?
Sane is offline   Reply With Quote
Old Mar 26th, 2008, 4:32 PM   #17
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
Re: Simple PHP Search Script

No, a friend gave me the script to practice on.

Now- I believe that solves everything really. Now I need to figure out how to make the outputed searched material have a link to a review page for that website, a link to the website, a rating of the website and somehow have keywords for each data...
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.
Arnack is offline   Reply With Quote
Old Mar 26th, 2008, 7:26 PM   #18
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
Re: Simple PHP Search Script

I'm actually just going to scratch the search thing and think up a whole new idea for my website...
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.
Arnack is offline   Reply With Quote
Old Apr 1st, 2008, 12:18 PM   #19
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Re: Simple PHP Search Script

Yo, mods. I see spam.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 1st, 2008, 12:28 PM   #20
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,623
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
Re: Simple PHP Search Script

taken care of Ooble
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP script ending prematurely causing Internal Error...??? Syntax_Error PHP 2 Feb 29th, 2008 8:42 PM
Parsing PHP script output bulio PHP 1 Feb 18th, 2008 6:41 PM
A simple script isn't working correctly scuzzman Perl 3 Dec 23rd, 2005 6:42 AM
A simple perl script satimis Perl 3 Aug 15th, 2005 9:31 AM
A simple script to execute a command package satimis Bash / Shell Scripting 3 Aug 12th, 2005 11:28 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:21 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC