cant connect my results page to connect with mysql database - Help!
#1
Posted 05 January 2013 - 12:15 AM
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
Posted 05 January 2013 - 12:43 AM
#3
Posted 05 January 2013 - 08:40 AM
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
Posted 05 January 2013 - 05:32 PM
#5
Posted 05 January 2013 - 05:40 PM
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
Posted 05 January 2013 - 05:45 PM
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
Posted 05 January 2013 - 05:48 PM
Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf *
Random Quote:
"
#8
Posted 05 January 2013 - 06:05 PM
#9
Posted 05 January 2013 - 06:18 PM
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
#11
Posted 05 January 2013 - 06:21 PM
name, title, description, connect, link
Regards
#12
Posted 05 January 2013 - 06:47 PM
[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
Posted 05 January 2013 - 10:26 PM
That first error message indicates the connection failed. What error, if any, do you get if you use "localhost"?
#14
Posted 05 January 2013 - 10:33 PM
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
Posted 05 January 2013 - 10:41 PM
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
Posted 05 January 2013 - 10:59 PM
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.
#17
Posted 05 January 2013 - 11:05 PM
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
Posted 05 January 2013 - 11:14 PM
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.
#19
Posted 05 January 2013 - 11:25 PM
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
Posted 06 January 2013 - 06:24 PM
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












