Can't connect my online test PHP results page to mysql database - Please Help !!

[size=10pt][font=comic sans ms]Hi all and Happy New Year
Hope you all had a fantastic time

First time here so hopefully someone can help
I was up to 5.55 am last night trying to get my search engine box to work.

I have followed a tutorial in putting a search engine on a webpage.
I created my database with 5 fields etc…, all went well
I made a search page and I made the results page.
I uploaded them to a folder call testengine ( I haven’t connected it to my site, it just stands alone for testing)

My problem is I know I’ve got it wrong for the results page to connect to the database but can’t figure it out.

I have on the results page the following php code:
[php]mysql_connect(“localhost”, “root”, “”);
mysql_select_db(“databasefirst”); [/php]

I am getting the errors in my lines 36 and 37 which means its the two lines quoted above.
I have changed localhost to other names including ‘localhost8080’, ‘localhost:8080’, ‘www.mydomainname.co.uk’,
My username is ‘root’ and my password is blank just the usual.

I logged into ‘localhost/myphpadmin’ and made the database.
I watched the tutorial and made the pages but I also downloaded the files as the tutorial allowed me to look at the code.
There were a couple of corrections that I had to make but everything seems fine, it’s just connecting.

Below I will add the full PHP from my results page and after that the results that occured.
p.s. the address I’ve put down as ‘domain’ as I’ve hidden my own address I’m not to sure if I would be allowed to show my own domain on forum post[/font][/size]

TEST PAGE CODE

[code] < form action=http://www.domain.co.uk/testengine/results.php" method=“get”>
<input type=“text” name=“input” size=“50” value=’<?php echo $_GET ['input']; ?>’ class=“search-field” />


[/code]

[php]<?php
$input = $_GET[‘input’];//Note to self $input in the name of the search field
$terms = explode(" ", $input);
$query = "SELECT * FROM search WHERE " ;

foreach ($terms as $each) {
$i++;
if ($i == 1)
$query .= "keywords LIKE ‘%each%’ ";
else
$query .= "OR keyword LIKE ‘%each%’ ";
}

// connect to database below
mysql_connect(http://www.domain.co.uk, “root”, “”);
mysql_select_db(“databasefirst”); // database name is databasefirst
$query = mysql_query ($query);
$numrows = mysql_num_rows($query);
if ($numrows > 0){

while ($rows = mysql_fetch_assoc($query)){
$id = $row[‘id’];
$title = $row[‘title’];
$description = $row[‘description’];
$keywords = $row[‘keaywords’];
$link = $row[‘link’];
echo “

$title


$description

”;

}

}

else
echo “No Results Found for “$input””;

// disconnect
mysql_close();

?>
[/php]

RESULTS AFTER RUNNING TEST

Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host ‘http’ (1) in /home/545/connery/www.domain.co.uk/public_html/testengine/results.php on line 36

Warning: mysql_select_db() [function.mysql-select-db]: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2) in /home/545/connery/www.domain.co.uk/public_html/testengine/results.php on line 37

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/545/connery/www.domain.co.uk/public_html/testengine/results.php on line 37

Warning: mysql_query() [function.mysql-query]: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2) in /home/545/connery/www.domain.co.uk/public_html/testengine/results.php on line 38

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/545/connery/www.domain.co.uk/public_html/testengine/results.php on line 38

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/545/connery/www.domain.co.uk/public_html/testengine/results.php on line 39
No Results Found for “contact”
Warning: mysql_close(): no MySQL-Link resource supplied in /home/545/connery/www.domain.co.uk/public_html/testengine/results.php on line 60

[size=10pt][font=comic sans ms]
Can anyone help, I am a novice but slowly getting there, I think !!!

Regards

Glasgow-Guy[/font][/size]
:slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service