Clicky

On my site I want to put a search box in which the customer will enter a 4 figure type mumber.
The search should return a link which will take him to a pdf document.

The links are in a MySQL data base as follows: (example)
Type number     link
1234                  www.sowter.co.uk/colours/1234.pdf

Could somebody let me have some sample code which I can build into my site. www.sowter.co.uk
Thanks.

asked 12/13/2011 02:52

BrianSowter's gravatar image

BrianSowter ♦♦


6 Answers:
Try this:

1:
2:
3:
4:
<!-- Your HTML file goes here -->
<form action="search.php" method="GET">
<input type="text" name="typenum"><input type="submit" value="Search">
</form>


1:
2:
3:
4:
5:
6:
7:
8:
// search.php file goes here
// Make sure you have connected to database before this line
$type_num = addslashes($_GET['typenum']);
$sql = "SELECT type_number, link FROM table_name WHERE type_number = {$type_num}";
$res = mysql_query($sql);
while (($row = mysql_fetch_assoc($res)) !== FALSE) {
    echo "<a href='" . $row['link'] . "'>Link to PDF</a><br>";
}
link

answered

StingRaY's gravatar image

StingRaY

Thanks this looks very promising.
I think the db is password protected.  How do I connect to the DB?

I am just going out but I would love to have something to work on tomorrow.  Thanks
brian
link

answered 2011-12-13 at 11:12:22

BrianSowter's gravatar image

BrianSowter

To connect to db:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
// Setting of your MySQL connection.
// If you do not have these information, ask your web administrator. He should know this.
$host = "";
$username = "";
$password = "";
$dbname = "";

// Then connect
mysql_connect($host,$username,$password);
mysql_select_db($dbname);
link

answered 2011-12-13 at 11:21:48

StingRaY's gravatar image

StingRaY

add following code to connect to db before // Make sure you have connected to database before this line

Regards,
Abhijit
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
<?php


/* Database config */

$db_host		= 'localhost';
$db_user		= 'cart';
$db_pass		= 'cart';
$db_database	= 'store'; 

/* End config */



$link = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');

mysql_select_db($db_database,$link);
mysql_query("SET names UTF8");
link

answered 2011-12-13 at 11:27:18

webmatrixpune's gravatar image

webmatrixpune

If you "think" the database is password protected, then you do not know the password. What webmatrixpune wrote is all true, but you have to know the password to the database tofetch the data from it.
link

answered 2011-12-13 at 11:27:45

Roads_Roads's gravatar image

Roads_Roads

Thanks for your help
link

answered 2011-12-13 at 12:22:23

BrianSowter's gravatar image

BrianSowter

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×2

Asked: 12/13/2011 02:52

Seen: 237 times

Last updated: 12/17/2011 06:29