Solved

mysql_connect();  error

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
The viewer will learn how to count occurrences of each item in an array.

760 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

17 Experts available now in Live!

Get 1:1 Help Now