Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

mysql_connect();  error

Posted on 2000-03-11
3
275 Views
Last Modified: 2010-05-18
I using the following code for inserting values into a table, but I am getting error

Warning: MySQL Connection Failed: Unknown MySQL error in /www/xyz.com/sona/dat1.php3 on line 10
UNABLE TO CONNECT TO DATABASE

My code is


<html><head><title>Inserting Values</title></head>
<body>
<? $hostname="xyz.com";
$username="aaa";
$pass="ccc";
$dbhost="zzz";
mysql_connect($hostname,$username,$pass) OR DIE("UNABLE TO CONNECT TO DATABASE");
@mysql_select_db($dbhost) OR DIE("UNABLE TO select TO DATABASE");
$query = "insert into testtable values('$fname','$lname','$age')";
mysql_query($query);
mysql_close();
?>

<center>Values are inserted into database</center>
</body>
</html>

I am new to PHP pl help me

Tripat
0
Comment
Question by:tripat
3 Comments
 
LVL 2

Expert Comment

by:gravity
ID: 2607444
Hmm... can you connect to the mysql server in any other of your scripts, because that's quite obviously the problem here.
0
 
LVL 1

Author Comment

by:tripat
ID: 2607452
I am trying out the first script.
but I can connect to mysql server from telnet and have created the table there.
0
 

Accepted Solution

by:
jayy earned 50 total points
ID: 2608348
Hi tripat,
Is the server your running the php script on the same server thats running the MySQL?

If yes try using $hostname = "localhost";

Also I'm not sure but I think that you should have something like:

$dbId = mysql_connect(your stuff here);

so when you do your query you can pass it the database session Id example:

$result = mysql_query($query,$dbId);

Hope this is of some help.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question