Solved

mysql_connect();  error

Posted on 2000-03-11
3
265 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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.  …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now