Solved

mysql_connect();  error

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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

832 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