Jump to content

cant connect my results page to connect with mysql database - Help!


Glasgow-Guy

Recommended Posts

Hi all and Happy New Year

Hope you all had a fantastic time

 

It's 5.55 am here in the UK and I've been up for the past 4 hours 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:

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

mysql_select_db("databasefirst");

 

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 tuorial allowed me to look at the code.

There were a couple of corrections that I had to make but everything seems fine, its just connecting.

 

 

Can anyone help, I am a novice but slowly getting there, I think !!!

 

Regards

 

Glasgow-Guy

Link to comment
Share on other sites

Hi Bashy

Thanks fur reply.

 

Soz

 

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

 

 

TEST PAGE 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" />

 

 

<input type="submit" value="search" class="search-button" />

</form>

</center>

 

<hr />

<?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 "<h2><a href='$link'>$title</a></h2>

$description<br /><br />";

 

}

 

 

}

 

else

echo "No Results Found for \"<strong>$input</strong>\"";

 

// disconnect

mysql_close();

 

 

 

?>

 

 

 

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

 

 

 

 

Hope someone can help

 

Regards

 

Glasgow-Guy

Link to comment
Share on other sites

But can't remember for that particular site but I know the hosting company ofr that particular site do offer it but can't remeber if I have it for the site I have used so far.

 

I will add the testing pages to one of my other sites that has ssh and been developed to include its mysql database.

 

It's 22.39pm here so Ill have it changed over in 10 minutes

 

regards

Link to comment
Share on other sites

I have just changed it over, everything is the same but its now on a different server for one of my other websites.

On this site that I have included the test pages has its own mysql database that is working and was built for my by someone else.

I've just tested it and the following happened

 

Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'http' (1) in /home/17536/windowquote/www.domain.co.uk/public_html/testengine/results.php 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/17536/windowquote/www.domain.co.uk/public_html/testengine/results.php on line 34

 

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/17536/windowquote/www.domain.co.uk/public_html/testengine/results.php 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/17536/windowquote/www.domain.co.uk/public_html/testengine/results.php on line 36

 

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

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/17536/windowquote/www.domain.co.uk/public_html/testengine/results.php on line 37

No results found for "contact"

Warning: mysql_close(): no MySQL-Link resource supplied in /home/17536/windowquote/www.domain.co.uk/public_html/testengine/results.php on line 56

Link to comment
Share on other sites

Hi Pikachu 2000

 

No I suppose I dont

But its a test page for a search box and as stated above I'm a novice.

If I learn by my mistakes fine but as long as it doesn't effect the site then great.

 

The site that run with its mysql database is a buisness site, the search box that I would hope to eventually build and have working is for a free tourism site that is quite big and already running.

 

We would all love to have a great site that works perfectly and that never has problems with bad coding/wrong coding, hackers etc..

 

Wish I had one of the perfect sites but I have a very very long way to go before I feel in total control

 

 

Regards

 

Glasgow-Guy

Link to comment
Share on other sites

Yep, there is opened port 22 (SSH)

[jazzman@localhost ~]$ nmap -sT 217.8.240.25
Starting Nmap 5.51 ( http://nmap.org ) at 2013-01-05 18:42 EST
Nmap scan report for uniform.rb.xcalibre.co.uk (217.8.240.25)
Host is up (0.12s latency).
Not shown: 995 filtered ports
PORT    STATE  SERVICE
21/tcp  open   ftp
22/tcp  open   ssh
25/tcp  open   smtp
80/tcp  open   http
443/tcp closed https
Nmap done: 1 IP address (1 host up) scanned in 7.28 seconds

 

You can try to log in trying to use FTP password or if you remember something about that.

If your log in has been successfully you could be obtain an information about database without to log in.

Link to comment
Share on other sites

I fail to see what that has to do with anything. The problem is that the database connection is not coded correctly. You do not use the "http://" scheme for logging in to a mysql database. On most hosts you just use "localhost", sometimes you can use the actual domain name (without the "http://" scheme and without the "www." subdomain)

 

That first error message indicates the connection failed. What error, if any, do you get if you use "localhost"?

Link to comment
Share on other sites

Hi David AM

 

I have justed chnage my 'domain name' with the the word 'domain'

 

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/17536/windowquote/www.domain.co.uk/public_html/testengine/results.php 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/17536/windowquote/www.domainco.uk/public_html/testengine/results.php on line 34

 

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/17536/windowquote/www.domain.co.uk/public_html/testengine/results.php 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/17536/windowquote/www.domain.co.uk/public_html/testengine/results.php on line 36

 

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

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/17536/windowquote/www.domain.co.uk/public_html/testengine/results.php on line 37

No results found for "contact"

Warning: mysql_close(): no MySQL-Link resource supplied in /home/17536/windowquote/www.domain.co.uk/public_html/testengine/results.php on line 56

 

 

Regards

 

Glasgow-Guy

Link to comment
Share on other sites

My localhost is on :8080

So I have tried the following code on the results page and they all bring up errors

 

 

 

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

mysql_select_db("databasefirst");

 

and

 

mysql_connect(“localhost:8080”, "root", "");

mysql_select_db("databasefirst");

 

and

 

mysql_connect(“localhost8080”, "root", "");

mysql_select_db("databasefirst");

Edited by Glasgow-Guy
Link to comment
Share on other sites

Port 8080 is an alternate HTTP port. HTTP is the Hyper Text Transport Protocol which is used for WEB pages. Connecting to a mySql database server has NOTHING to do with HTTP.

 

The error message indicates a problem with the configuration. Perhaps the mySql socket is not where PHP thinks it is. I think you need to talk to your host about this. It may require a change to the mySql configuration file or the PHP configuration file, or both.

 

Give them the complete text of that first error message, and see what they say.

Link to comment
Share on other sites

Hi DavidAm Thanks for the quick reply

 

I think your right, it could go on and on if I dont.

The site is already configured with mysql but is working on a different database that I don't know much about.

I threw the pages onto that site as I know its already running a mysql database.

 

Ive only uploaded the search box test pages to throw myself in the deep end and see if it can work.

I still don't fully understand mysql databases yet, but I'll get there.

 

I've got quite a few tutorials to go through so I'll suppose I'll get on it

 

 

Thanks

 

Glasgow-Guy

Link to comment
Share on other sites

If you know there are other PHP scripts using the database, you might hunt down the connection code they are using. It might give you a clue.

 

Basically, the process is: 1) Connect to db server, 2) Select Database, 3) run queries.

 

You are not getting past step one, so the fact that you are using a different database is not significant (yet). If there are other scripts that do get past step 1, then the configuration may not be wrong. It may be that the "host" name needs to be very specific or include or port number or something. Looking at a working script my give you the hint.

Link to comment
Share on other sites

Thanks DavidAm

 

Truly appreciated.

I do think it will be back onto the learning drawing board.

I admit I'm only just starting out and its enjoyable working it out etc..,

I'm at a level of html, xhtml, css and well into javascript, so im onto php,mysql and taking a peek at others while i progress.

 

But as you know, it's learning each steps and not jumping too far ahead which maybe I'm doing. sometimes it works! sometimes it doesn't!

 

Forums like these are great because its people who are well far advanced that take time out ot help the novices learn

 

 

Regards

 

Glasgow-Guy

 

No matter what keep learning

Link to comment
Share on other sites

My point to use SSH was to get a list of your database names (or create a new one) using only SSH, but it seems in that particular shared web hosting environment, the databases are hosted on a separate server.

No one of us couldn't help you in this situation.

Edited by jazzman1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.