473,396 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

can't connect to mysql

Hi,

I am writing a login page but the php code to authenticate user is not working.

My login web page calls 'action="xLoginCheck.php"'. Below is the php code. I am writing to a log file to trace program flow.
I know it is ok up to the "hoho" bit. This code(version1) works.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $host="localhost"; // Host name 
  3. $username="****"; // Mysql username 
  4. $password="****"; // Mysql password 
  5. $db_name="accounts"; // Database name 
  6. $tbl_name="userstbl"; // Table name 
  7.  
  8. $FileName = "log.txt";
  9. $FileHandle = fopen($FileName,'w') or die("can't open file");
  10. fwrite($FileHandle, "hoho\n");
  11. fclose($FileHandle);
  12. ?>
  13.  
This code(version2) doesn't work, ie when I add the mysql_connect bit. Nothing inside the mysql_connect {} appear on the screen or the log file. I just get error page that says "website cannot display page"


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $host="localhost"; // Host name 
  3. $username="****"; // Mysql username 
  4. $password="****"; // Mysql password 
  5. $db_name="accounts"; // Database name 
  6. $tbl_name="userstbl"; // Table name 
  7.  
  8. $FileName = "log.txt";
  9. $FileHandle = fopen($FileName,'w') or die("can't open file");
  10. fwrite($FileHandle, "hoho\n");
  11.  
  12. if (!$connection = mysql_connect($host, $username, $password))
  13. {
  14.   $message = mysql_error();
  15.   fwrite($FileHandle, $message);
  16.   fclose($FileHandle);
  17.   die();
  18. }
  19.  
  20. ?>
  21.  
Can anyone see where the problem is?? What is the best way to trace php code???

thanks
Aug 23 '10 #1
7 1922
TheServant
1,168 Expert 1GB
Firstly, you should probably **** out your password as good practice for public forums.

It might be legal, but your if condition on line 12 looks a bit sus. Humour me and try:
Expand|Select|Wrap|Line Numbers
  1. $connection = mysql_connect($host, $username, $password);
  2. if (! $connection) { 
  3.   $message = mysql_error(); 
  4.   fwrite($FileHandle, $message); 
  5. }
  6. fclose($FileHandle);
Also, you were only closing the file if it failed to connect.
Aug 23 '10 #2
thanks for your reply !!

I will replace user. Tried your suggestion but all I get in the log is "hoho 22". I have added an else line.

I am sure mysql server is working because I can login using the administrator tool.

I have just installed Apache, MySQL and PHP. Could it be it can't find the mysql db?? Where do i check??

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $host="localhost"; // Host name 
  3. $username="****"; // Mysql username 
  4. $password="****"; // Mysql password 
  5. $db_name="accounts"; // Database name 
  6. $tbl_name="userstbl"; // Table name 
  7.  
  8. $FileName = "log.txt";
  9. $FileHandle = fopen($FileName,'w') or die("can't open file");
  10. fwrite($FileHandle, "hoho 22\n");
  11.  
  12. $connection = mysql_connect($host, $username, $password);
  13. if (!$connection)
  14. {
  15.   $message = mysql_error();
  16.   fwrite($FileHandle, $message);
  17. }
  18. else
  19. {
  20.   fwrite($FileHandle, "ok");
  21. }
  22.  
  23. fclose($FileHandle);
  24. ?>
  25.  
Aug 23 '10 #3
TheServant
1,168 Expert 1GB
Try run a script like this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
  3. if (!$link) {
  4.     die('Could not connect: ' . mysql_error());
  5. }
  6. echo 'Connected successfully';
  7. mysql_close($link);
  8. ?>
What (if any) output do you get?
Aug 23 '10 #4
Tried your suggestion and I am getting Server Error. See attached.

Which server is in error??

The Apache server? When I "http://localhost/index.php" I get the right stuff on the screen.

The MySQL server? I can login using the mysql administrator tool.

Is there another server I don't know about?

thanks
Attached Images
File Type: jpg err.jpg (25.9 KB, 146 views)
Aug 24 '10 #5
Dormilich
8,658 Expert Mod 8TB
does the same happen in Firefox, Safari, Chrome or Opera?
Aug 24 '10 #6
I have installed Apache, MySQL and PHP on my own PC a few days ago. I have done this so I can learn PHP and web development. This is the first time I am accessing MySQL using PHP since the install. Everything happens on my PC only. I use Internet Explorer (Windows 7) and I don't use these other web browsers.

I have been surfing for an answer and several people suggest, in php.ini, uncommenting

;extension=php_mysql.dll

but my php.ini file only has

;extension=msql.dll

Is this a problem? If I go ahead and uncomment this line it is worse.

I cannot find 'php_mysql.ddl' or 'msql.dll' on my computer. But then I am new to Windows 7 and I am not sure how to search for a file properly

I have a feeling PHP doesn't know where to find MySQL. What to do???
Aug 24 '10 #7
johny10151981
1,059 1GB
your server giving 500 error. Its server internal error. make sure your server is working properly
Aug 24 '10 #8

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

Similar topics

0
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...
0
by: Ryan Stewart | last post by:
I'm running MySQL server on a WinXP box at home. I have a cable modem/router. I've set up port forwarding on port 3306 to the machine running MySQL. I can connect locally just fine, but when I try...
3
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...
1
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...
0
by: ryanmhuc | last post by:
I have root access to this server which has been preconfigured. I can connect using the mysql command tool. But I cannot connect using any mysql GUI software (I am currently tunneling the 3306 port...
2
by: xiuchuanli | last post by:
I install Fedora 4 with web server, after that I installed mysql 5.0.15. Now I can connect to mysql from command line and mysql-administrator and mysql-query-browser. But when I try to test to...
0
by: xiuchuanli | last post by:
I install Fedora 4 with web server, after that I installed mysql 5.0.15. Now I can connect to mysql from command line and mysql-administrator and mysql-query-browser. But when I try to test to...
1
by: linux | last post by:
Sorry if this is a really dumb question. I am trying to connect to our remote MySQL server (which is running just fine). I have a perl script which worked just fine on my other Fedora 4 box (all...
3
by: likigoldenstar | last post by:
Hi, I have some problem in developing program using PHP. I 'll explain my platforms: I use appserv-win32-2.5.9 as a app server. In the server, mysql client version is 5.0.37 Problems:
5
by: scorpionbilli | last post by:
Hi, The local mysql server is running on my Macbook. I can access it through the console client: $ mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.