473,664 Members | 3,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php script can't connect to local mysql, what the heck?

35 New Member
Okay so I am at a loss here. I have a website that I've previously had no trouble connecting to the mysql DB on. I have an include to a connect file with the relevant connection info, and it was working fine until today. I am trying to implement some ajax with the javascript framework mootools (although I don't see how this is causing the problem it started happening right around this time sooo...)

I am sending info from my login form to the processLogin.ph p page, which in turn logs me in and everything, and then is supposed to write new info to the relevant div which sent the call.

But my processLogin page started saying it "couldn't connect to the localhost", which most definitely is not my intent nor have it set it to. So I included the connect.php page on the page itself; nothing. It still had a mistake (occurring right at my first query). So I wrote the connection info directly before the query, and no longer receive that error, but still no data. I echo'd the query and get nothing. So, here is the connect.php code I include in index.php, so it can call it each time:
[PHP]<?php
$dbServer = 'mysql***.secur eserver.net';
$dbDatabase = '****;
$dbUser = '****';
$dbPass = '****';

// Connect to database
$db = mysql_pconnect( $dbServer, $dbUser, $dbPass) or die("Couldn't connect to database due to error in page: " . mysql_error());
mysql_select_db ($dbDatabase, $db) or die("Couldn't select database due to error in page: " . mysql_error()); ?>[/PHP]

Neither of these error message ever appear, btw, meaning the connection is working here.

Here is the code that is throwing the error:
[php]$sql = mysql_query("SE LECT * FROM users WHERE username=" . $username . " AND password=" . $password . " AND activated='1'") ;
echo 'sql=' . $sql;
$login_check = mysql_num_rows( $sql);[/php]

Where I echo sql=$sql, I get "sql=" and nothing else, and this is the error message:

Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in /blahblahblah on line 51.
And finally, when I include the connect info instead of writing it straight to the page (and I'm including it to the page, as opposed to index.php [where I normally include it]):

Warning: mysql_query(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /webpage on line 47
Sorry for the lengthy first post, but I wanted to get all relevant info out there.
My guess is it's because I'm calling for the page through ajax, but I can't figure out how that causes the problem or how to fix it. Any ideas or help MUCH appreciated!
Nov 19 '06 #1
4 3761
ronverdonk
4,258 Recognized Expert Specialist
Let's start with the select statement. I assume that the userid and password are CHAR fields, so you'll have to include them within quotes. The entire select string incl. the variables van be code in one double-quote enclose string. So your statement is:
[php]$sql = mysql_query("SE LECT * FROM users WHERE username='$user name' AND password='$pass word' AND activated='1'")
or die("Invalid query: " . mysql_error());
[/php]
Ronald :cool:
Nov 19 '06 #2
d3vkit
35 New Member
Let's start with the select statement. I assume that the userid and password are CHAR fields, so you'll have to include them within quotes. The entire select string incl. the variables van be code in one double-quote enclose string. So your statement is:
[php]$sql = mysql_query("SE LECT * FROM users WHERE username='$user name' AND password='$pass word' AND activated='1'")
or die("Invalid query: " . mysql_error());
[/php]
Ronald :cool:
Ah, you're right about that... but it still didn't quite fix it. When I write the connect script into the page, it works; when I include the script, it doesn't. Is this some sort of scope that I don't understand? Can it not connect to an included script with ajax maybe?
Well, it works, but not as well as I'd like, but I suppose it's all the same. Thank you for your help; I can't believe I didn't see that.
Nov 20 '06 #3
ronverdonk
4,258 Recognized Expert Specialist
Is the connect script, the one that you include, in a different path from the script that includes it and, if so, are you correctly backtracking or forward tracking the include. E.g. if the connect script is one dir below (child dir) the including script, you must include it as [php]include('connec t/dbinclude.php"' );[/php].
If it is in a dir above (parent dir) the including script you define [php]include('../dbinclude.php"' );[/php].
If it is in another dir down from the one above you (sibling dir), you do [php]include('../connect/dbinclude.php"' );[/php].
Is that the reason?

Ronald :cool:
Nov 20 '06 #4
d3vkit
35 New Member
Is the connect script, the one that you include, in a different path from the script that includes it and, if so, are you correctly backtracking or forward tracking the include. E.g. if the connect script is one dir below (child dir) the including script, you must include it as [php]include('connec t/dbinclude.php"' );[/php].
If it is in a dir above (parent dir) the including script you define [php]include('../dbinclude.php"' );[/php].
If it is in another dir down from the one above you (sibling dir), you do [php]include('../connect/dbinclude.php"' );[/php].
Is that the reason?

Ronald :cool:
I'm sorry I never replied to you; I was going to that night, then got busy and it never let up apparently.

Just wanted to say thanks for the suggestions. I went to the code, did the include as I normally would (backtracking to the scripts directory), and it worked no problem. No idea what I was doing wrong before, but it's all sorted out now. Seemed I had done this in the first place, but oh well. I do appreciate thehelp; I learned that I don't need to include variables in my mysql call with periods. Forgot what that's called. Dang it.
Dec 14 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2884
by: steve | last post by:
Hi, I finally figured out the best way to synch local and remote script folders, containing many php script files. What I used to do before was try to ftp all the changed files, etc. which was tedious and often broke. It was also very slow. What I do now is to pkzip the folder up, ftp the pkzip’ed data to remote, and then unzip it there, which recreates the directories and files.
1
2581
by: Peter Nikolaidis | last post by:
Greetings, I am attempting to get MySQLdb 0.9.2 installed on Mac OS 10.2 with a Fink distribution of Python 2.2.2. I have seen only a few posts on the subject, some of them relate to "conflicting header files," but I don't know what to do about conflicting header files, or where I would find them, and once I found them, which ones to remove. I have compiled MySQL 4.1 and installed into /usr/local/mysql, but since have moved to a Fink...
0
2404
by: Bill Hernandez | last post by:
Hi, I've been writing software on the mac since 1987, but am brand new at unix/php/mysql, and that's where I'm headed so I'm reading everything I can get my hands on, but like anything else there's going to be a learning curve, that having been said... I followed the install instructions at http://entropy.ch , and was able to get mySql & php installed on my G4 -> (OSX 10.2.6) last night. I downloaded Navicat and setup a password for...
0
3284
by: Ian | last post by:
Dear All, I just downloaded & installed MYSQL. It seemed to work and I can start it and enter my password and change a directory but that is about all. I have been ready and playing "hit & miss" all afternoon and it seems to have something to do with the "mysql_install_db" not being installed correctly -- I have tried multiple installs with multiple downloaws. My log. . .
3
17795
by: Pugi! | last post by:
On a freshly installed Fedora C3 (incl. webserver apache php mysql) i get the following problem when connecting to mysql through a browser (phpMyAdmin): : #2002 Can't connect to local MySQL server through socket /var/lib/mysql/mysql.sock On the website of MySQL this error is mentioned but I found no solution. In /var/log/messages the following log occurs :
1
121524
by: jiing | last post by:
Now let me describe what I have done and my purpose: Originally, I want to user ports to install phpBB But I found that phpBB doesn't support mysql 5.x (but the ports installed mySQL 5.0.0 alpha) so I deinstall mysql5-server and mysql5-client And then I install mysql41-server and mysql41-client on FreeBSD 5.3 by ports but now , mysql is not workable
5
1750
by: news | last post by:
I have a new situation I'm facing and could use a suggestion or two, as I don't seem to be able to think in the abstract very well. We have a local server which holds all of our image files. We have a remote server that runs our public Web server and mySQL database. I need to be able to run a script that will: Read the contents of a dir on the local server and a. make thumbnails of the files in it b. querey the database and pull...
14
6109
by: mistral | last post by:
Need php script to create mySQL database programmatically; since hosting configuration may not allow create database from script, script also need eliminate/rewrite all restrictions in appropriate places in that hosting.
1
8697
by: sasimca007 | last post by:
Hi friends, I installed mysql in ubuntu but, i don't know how to connect to that mysql. Actually we connect to postgresql by psql command, but when i tried to connect mysql with mysql command but it displaying this error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when i give mysql databasename it displaying the following error: Can't connect to local MySQL...
0
8437
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7375
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4185
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1759
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.