Search
Left Quote    Every day I get up and look through the Forbes list of the richest people in America. If I
- Robert Orben    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Search
  This user is offline  Genius
  Subject: "Search" Posted: @ 2:02 am on Mar 17 2008   

Member #: 582
Rank: User - (77)
Since: 02/18/08
Posts: 76
From: kmmk

Ok, I created a simple search script that would look up game keys. But ran into a problem.

My code:

Code:
<?php
include('db_con nect.php');

if (@$_POST['searc h']=="sear ch")
{
$game=$_POST['g ame'];
$key=$_POST['ke y'];
$info=mysql_que ry("SELECT * FROM 'keys' WHERE 'key' = '%$key%' AND 'game' = '%$game%' AND 'confirmed' = 'yes'"); while ($tables = mysql_fetch_arr ay($info))
{
$key=$tables['k ey'];
$game=$tables[' game'];
$result = "Key: ".$key.&qu ot; Game: ".$game.&q uot;";
header("Lo cation: index.php?searc h=".$resul t."") ;
exit;
}
} else {
$result = "Sorry, your key is not in our database. Please research again in a week.";
header("Lo cation: index.php?searc h=".$resul t."") ;
exit;
}
?>



I inserted a cdkey into db but its keeps saying that we don't have your cd key...bla bla.

How can I fix this?

P.S: It would help me and others if someone makes search script tutorial :D


    Viewed: 8,807 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Search" Posted: @ 3:11 am on Mar 17 2008    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

I think your query may need adjusting... search google for SQL and LIKE condition.

I think it would be something like this:

SELECT * FROM `table` WHERE `column_name` LIKE '%chars%';

where the %chars% would be your search term. Give that a shot. I haven't really built any search scripts before so I can't help too much.




-bs0d | AllSyntax.com

    Viewed: 8,801 Times | Reply to This | To top
  This user is offline  Genius
  Subject: "re: Search" Posted: @ 3:53 am on Mar 17 2008    

Member #: 582
Rank: User - (77)
Since: 02/18/08
Posts: 76
From: kmmk

Ok, I got it fixed. Most of the part. Getting this error: 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 'keys (key, date, game, confirmed) VALUES ('464819348713 1', now(), 'StarCraft', '' at line 1

Line it accurs is:

Code:

$insert = "INSERT INTO keys (key, date, game, confirmed) VALUES ('$key', now(), '$game', 'no')";
$insert2 = mysql_query($in sert);
if(!$insert2) die(mysql_error ());
$result = "We could not find $key for $game in our database." ;;
header("L ocation: index.php?error =".$resul t."" ;
exit;
}
?>



EDIT: Nevermind! Got it working.



Edited at 02:36:30 am on 03/19/08


    Viewed: 8,796 Times | Reply to This | To top
  This user is offline  Genius
  Subject: "re: Search" Posted: @ 2:09 am on Mar 21 2008    

Member #: 582
Rank: User - (77)
Since: 02/18/08
Posts: 76
From: kmmk

Ok, can someone teach me how to filter out dashes from search query?

For example, I want to have php automatically remove the dash or (-) from the query. So if I type in 38328-34324-342 324 the script should eliminate (-) and should search db with 383283432434232 4. Thanks.




    Viewed: 8,727 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Search" Posted: @ 3:51 am on Mar 21 2008    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

you can probably use str_replace(); like this:


Code:


$var = 38328-34324-342 324;

$var = str_replace(&q uot;-", "", $var);

*Note that str_replace(); is case sensitive.




-bs0d | AllSyntax.com

    Viewed: 8,718 Times | Reply to This | To top
  This user is offline  Genius
  Subject: "re: Search" Posted: @ 4:22 am on Mar 21 2008    

Member #: 582
Rank: User - (77)
Since: 02/18/08
Posts: 76
From: kmmk

Thanks, it worked




    Viewed: 8,715 Times | Reply to This | To top
  This user is offline  boy
  Subject: "re: Search" Posted: @ 3:24 am on May 13 2008    
Member #:
Since: 01/01/70
Posts:

I'm trying to make simple search script that has some search options such as search by firstname or search by nickname,etc.
I used selection button in the form to choose search option, and my question is
"is there any way that I can only go in one query that only need to be changed conditoion ?"
=============== ===============
I have form like,
<form name="sea rch" method="p ost" action="s earchresults.ph p">
Search for <input type="tex t" name="fin d" />
By <Select name="fie ld">
<Option value="fn ame">F irst Name</option >
<Option value="ln ame">L ast Name</option >
</Select> ;
<input type="hid den" name="sea rching" value="ye s" />
<input type="sub mit" name="sea rch" value="Se arch" />
</form>
--------------- ----------
and in searchresult.ph p,
//After connection to DB
$find = strtoupper($fin d);
$find = strip_tags($fin d);
$find = trim ($find);

$query = "select * from profile where upper($field) like '%$find%' ";

$result = mysql_query($qu ery);

$a = mysql_num_rows( $result);
--------------- -------------
But in here $a returns 0, which means the query seems not working as I expected.
Is anyone know how to make query in this case???



Edited at 10:27:14 am on 05/13/08


    Viewed: 8,236 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank