Search Engine Box not connecting with mysql database

[FONT=Comic Sans MS][SIZE=3]Hi all and Happy New Year
Hope you all had a fantastic time

I have just joined so I’m hoping someone can help this novice
I was up till 6am this morning trying to get my search engine box to work.

I have followed a tutorial in putting a php search engine box on a webpage and have it work.
I created mysql database with 5 fields etc…, all went well
I made a search page (index.php) and I made the results page (results.php).
I uploaded both files into my website inside a folder called testengine ( I haven’t connected it to my site, the folder 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:

mysql_connect("localhost", "root", "");

I am getting the errors in my lines 36 and 37 which means it’s the two lines quoted above.
I have changed localhost to other names including ‘localhost8080’, ‘localhost:8080’, ‘’,
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 too sure if I would be allowed to show my own domain on forum post[/SIZE][/FONT]

## TEST PAGE CODE ## which includes php code is ##

<h1 style="color:#00F" font-size="36px">SearchEngine</h1>
<form action="" method="get">
 <input type="text" name="input" size="50" value='<?php echo $_GET['input']; ?>' class="search-field" />
 <input type="submit" value="search" class="search-button" />
 <hr />

		$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){
			if ($i == 1)
				$query .= "keywords LIKE '%$each%' ";
				$query .= "OR keywords LIKE '%$each%' ";
		// connecting to our mysql database
		mysql_connect("", "root", "");
		mysql_select_db("databasefirst");  // database name is databasefirst
		$query = mysql_query($query);
		$numrows = mysql_num_rows($query);
		if ($numrows > 0){
			while ($row = mysql_fetch_assoc($query)){
				$id = $row['id'];
				$title = $row['title'];
				$description = $row['description'];
				$keywords = $row['keywords'];
				$link = $row['link'];
				echo "<h2><a href='$link'>$title</a></h2>
				$description<br /><br />";

			echo "No results found for \\"<b>$input</b>\\"";
		// disconnect


Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host ‘http’ (1) in /home/545/connery/ on line 33

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/ on line 34

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/545/connery/ on line 34

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/ on line 36

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/545/connery/ on line 36

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/545/connery/ on line 37
No results found for “contact”
Warning: mysql_close(): no MySQL-Link resource supplied in /home/545/connery/ on line 56

[FONT=Comic Sans MS]
Can anyone help, I am a novice but slowly getting there, I think !!!



My username is ‘root’ and my password is blank just the usual.

This is normal for a DIY download and install of Mysql on your own development machine (though you are warned not to use root, and to set yourself a password).

However it is not normal for a hosted web server with a Mysql server running on it – it would be far too easy to break in and damage the data.

In the first instance check the admin panel supplied by your hosting supplier, and your welcome emails, else, contact your hosting company and ask what your Mysql credentials are and how best to reference the localhost (domain, localhost, port 3306 etc) in your scripts.

In most cases the host should be ‘localhost’ so try this:

mysql_connect("localhost", "root", ""); 

and show us the results. I would guess that it’s a problem with the username or password but if you get the host right the error should explain all.

By the way, the reason you’re getting the error Unknown MySQL server host ‘http’ is that anything after the : is taken as being the port. But as long as you’re connecting to a database on the same server you shouldn’t need to specify an address other than localhost anyway.

Probably just as well it isn’t connecting, I can see from the errors what your domain is, and from your code you have no protection against mysql injection, it would be trivial for somebody to delete your entire database. Please read up on mysql injection and sanitising user input before you go live with your sites.