Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,073 members, 7,818,203 topics. Date: Sunday, 05 May 2024 at 10:16 AM

Please Help Me With This Search Script - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Please Help Me With This Search Script (738 Views)

Can Anyone One Give Me A Search Script, I Will Pay Top Naira For It. (2) (3) (4)

(1) (Reply) (Go Down)

Please Help Me With This Search Script by charliebiz(m): 7:49pm On Mar 04, 2009
please i need solution to the challenge i am facing with this code
This is actually what i want. I created a database and another page where information can be entered from the page into the database. Now, i am having problem creating a search page where users can enter a number or word and it will display the recordset or items in the row or the number. For example i entered 12345678 into my database and i now gave out this number to a client to search using my search script, what i would expect the person to get is the items on the recordset that follows the number 12345678 in the same row. Hope this is clear enough. this is the code i used for creating the search script bt it is not working a s i wanted it to.

This is the search page which is suppose to post the result on the same page
<?php
//This is only displayed if they have submitted the form
if ($searching =="yes"wink
{
echo "<h2>Tracking Results</h2><p>";

//If they did not enter a search term we give them an error
if ($courier == ""wink
{
echo "<p>You forgot to enter a search term";
exit;
}

// Otherwise we connect to our Database
mysql_connect("nevermind", "nevermind", "nevermind"wink or die(mysql_error());
mysql_select_db("nevermind"wink or die(mysql_error());

// We preform a bit of filtering
$courier = strip_tags($courier);
$courier = trim ($courier);

//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM tracking WHERE courier LIKE '$file'"wink;

//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo $result['file'];
echo " ";
echo $result['file'];
echo "<br>";
}

//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> " .$file;
}
?>

and this is the form
<form id="search" method="Post" action="<?=$PHP_SELF?>">
<p><img src="graphics/track1.jpg" alt="" width="161" height="140" align="left" /><img src="graphics/00_POD_side.gif" alt="" width="161" height="48" /></p>
<p>
<input type="text" name="file" />
</p>
<p>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="submit" />
</p>
<p>&nbsp;
</p>
</form>

Please i need urgent replies.
Re: Please Help Me With This Search Script by yawatide(f): 8:18pm On Mar 04, 2009
First off, kudos on the commenting.  I follow your code excellently.  Reminds me of my own code  cool

I see a lot wrong with your code above unfortunately.  So much so that I dare say it should be rewritten.  It seems like too much code for just one field.  Oh well.

Thiese might not solve the problem but consider the following, at the very least (hopefully these won't end up being that you didn't paste the code in its entirety):

1) you reference "courier". I don't see it in your form

2) $searching == "yes": it will always equal "yes".  Why not just use the submit form then do an isset() on the text field?

3)
echo $result['file'];
echo " ";
echo $result['file'];

why the repetition? Also, why not just do echo $result['file'] . " ". $result['file'] . "
"; ? each call to echo in your code is a separate call to the server. though it might not have an impact on your site, but on a major site, that could cos a lot of money.

Sorry for not replying directly but I believe in cleaning up things before I post an answer.  While I come up with one, someone might beat me to it but it's okay.  In the end, we all learn something wink
Re: Please Help Me With This Search Script by nitation(m): 8:32pm On Mar 04, 2009
@ poster

First of all, I cannot see anywhere you are checking for your submit button in this your code. You need something like this at the top of your page

if(isset($_POST['submit_button_name']))
{
// Basical validation, select, insert, update, etc comes in here
}

Moreso, all your codes rely on register_global. This was a feature removed from PHP as of version 4.2. You need to go back to www.php.net to read all about that. We are no longer gonna have register_globals in PHP6. Happy Easter kiss


Also, your <?=$php_self ?> should be the name of the file itself. $_SERVER['PHP_SELF'] is subject to attack. Name your file the actual page name. eg, <form action="nitation.php" method="post"></form>, etc


We are here to learn. Anyone offerring better solution should come forth.

-nitation
Re: Please Help Me With This Search Script by TechPros(m): 2:21pm On Mar 05, 2009
Note this it very important


Also, your <?=$php_self ?> should be the name of the file itself. $_SERVER['PHP_SELF'] is subject to attack. Name your file the actual page name. eg, <form action="nitation.php" method="post"></form>, etc

as yawa said earlier, i also can't find your reference to "courier". I don't see it in your form

smileyNow the solution to your Problem ( note i did not test run this)

just simply add that to your code ( note the changes )

<?php
//This is only displayed if they have submitted the form

$searching=$_POST['searching'];
$file=$_POST['file'];
if ($searching =="yes"wink
{
echo "<h2>Tracking Results</h2><p>";

//If they did not enter a search term we give them an error
if ($courier == ""wink
{
echo "<p>You forgot to enter a search term";
exit;
}


let me know if this work
Re: Please Help Me With This Search Script by nitation(m): 2:43pm On Mar 05, 2009
@Tech Pros

I observed you quoted my post. Was my explanation wrong?? Please kindly advice.

-nitation
Re: Please Help Me With This Search Script by yawatide(f): 3:42pm On Mar 05, 2009
nitation:
I think he was just saying that your quote is very important.

Seun:
Nice note. If as he says the number is unique, there is no need using LIKE. "=" will do. If on the other hand, it isn't unique and you are looking for something that resembles what you are looking for, plus or minus a few characters, then you may have to refine the LIKE search, as has been explained here: http://www.htmlite.com/mysql011.php - maybe that is why the query isn't returning anything.

poster:
You are yet to respond. Any luck? If no, I think a pasting of your db schema, showing example content, would help.
Re: Please Help Me With This Search Script by nitation(m): 3:45pm On Mar 05, 2009
Thanks Yawa. Didn't realise that

(1) (Reply)

Urgent Review Please ! / Pls Review This Site(Updated) / Care To Join The Startups?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.