Jump to content


Photo

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


  • Please log in to reply
19 replies to this topic

#1 Glasgow-Guy

Glasgow-Guy

    Member

  • Members
  • PipPip
  • 13 posts

Posted 05 January 2013 - 12:15 AM

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


#2 bashy

bashy

    Member

  • Members
  • PipPip
  • 19 posts

Posted 05 January 2013 - 12:43 AM

And the error is?

#3 Glasgow-Guy

Glasgow-Guy

    Member

  • Members
  • PipPip
  • 13 posts

Posted 05 January 2013 - 08:40 AM

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

#4 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,387 posts
  • LocationMississauga, Canada

Posted 05 January 2013 - 05:32 PM

Does your hosting provider provide you something like control panel or SSH access?

#5 Glasgow-Guy

Glasgow-Guy

    Member

  • Members
  • PipPip
  • 13 posts

Posted 05 January 2013 - 05:40 PM

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

#6 Glasgow-Guy

Glasgow-Guy

    Member

  • Members
  • PipPip
  • 13 posts

Posted 05 January 2013 - 05:45 PM

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

#7 Pikachu2000

Pikachu2000

    I hate everything.

  • Staff Alumni
  • 11,378 posts
  • LocationFuture Independent Republic of Texas
  • Age:106

Posted 05 January 2013 - 05:48 PM

Your host should have a section in their FAQs about how to properly connect to the database server, but surely you don't want to connect with the http protocol like you're trying to do now.
"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf *

Random Quote: "

#8 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,387 posts
  • LocationMississauga, Canada

Posted 05 January 2013 - 06:05 PM

Give us the domain name of that site to check which ports are open.

#9 Glasgow-Guy

Glasgow-Guy

    Member

  • Members
  • PipPip
  • 13 posts

Posted 05 January 2013 - 06:18 PM

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

#10 Glasgow-Guy

Glasgow-Guy

    Member

  • Members
  • PipPip
  • 13 posts

Posted 05 January 2013 - 06:19 PM

the page is http://www.pricequot...ngine/index.php

#11 Glasgow-Guy

Glasgow-Guy

    Member

  • Members
  • PipPip
  • 13 posts

Posted 05 January 2013 - 06:21 PM

the five fields for testing ( that should come up) are
name, title, description, connect, link

Regards

#12 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,387 posts
  • LocationMississauga, Canada

Posted 05 January 2013 - 06:47 PM

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.

#13 DavidAM

DavidAM

    Advanced Member

  • Gurus
  • 1,972 posts
  • LocationSpring, TX USA

Posted 05 January 2013 - 10:26 PM

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"?
-- I haven't lost my mind, it's backed up on tape ... somewhere!

#14 Glasgow-Guy

Glasgow-Guy

    Member

  • Members
  • PipPip
  • 13 posts

Posted 05 January 2013 - 10:33 PM

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

#15 Glasgow-Guy

Glasgow-Guy

    Member

  • Members
  • PipPip
  • 13 posts

Posted 05 January 2013 - 10:41 PM

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, 05 January 2013 - 10:42 PM.


#16 DavidAM

DavidAM

    Advanced Member

  • Gurus
  • 1,972 posts
  • LocationSpring, TX USA

Posted 05 January 2013 - 10:59 PM

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.
-- I haven't lost my mind, it's backed up on tape ... somewhere!

#17 Glasgow-Guy

Glasgow-Guy

    Member

  • Members
  • PipPip
  • 13 posts

Posted 05 January 2013 - 11:05 PM

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

#18 DavidAM

DavidAM

    Advanced Member

  • Gurus
  • 1,972 posts
  • LocationSpring, TX USA

Posted 05 January 2013 - 11:14 PM

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.
-- I haven't lost my mind, it's backed up on tape ... somewhere!

#19 Glasgow-Guy

Glasgow-Guy

    Member

  • Members
  • PipPip
  • 13 posts

Posted 05 January 2013 - 11:25 PM

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

#20 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,387 posts
  • LocationMississauga, Canada

Posted 06 January 2013 - 06:24 PM

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, 06 January 2013 - 06:24 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com