Solved

mysql_connect();  error

Posted on 2000-03-11
3
285 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
[X]
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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

726 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