mysql access denied and invalid mysql link resource.

Status
Not open for further replies.

sifaka

Member
Messages
46
Reaction score
0
Points
6
<?php
$username="sifaka@localhost";
$password="*********";
$database="sifaka_newdatabase";
$host="localhost";
$first=$_POST['first'];
$last=$_POST['last'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$web=$_POST['web'];
$message="process successful";
$connection = mysql_connect($host,$username,$password);
mysql_select_db($database,$connection) or die( "Unable to select database");


$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);
mysql_close();
?>

How do I fix this?

Thank you in advance!
sifaka
 

sifaka

Member
Messages
46
Reaction score
0
Points
6
chougard, I omitted the error messages from my first post. They should be helpful. And yes, I have created a database "sifaka_newdatabase" and a table titled "contacts". The error messages:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'sifaka@localhost'@'localhost' (using password: YES) in /home/sifaka/public_html/best_load_contacts.php on line 14

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/sifaka/public_html/best_load_contacts.php on line 15
Unable to select database

PHP:
<?php
$username="sifaka@localhost";
$password="*********";
$database="sifaka_newdatabase";
$host="localhost";
$first=$_POST['first'];
$last=$_POST['last'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$web=$_POST['web'];
$message="process successful";
$connection = mysql_connect($host,$username,$password);
mysql_select_db($database,$connection) or die( "Unable to select database");
 
 
$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);
mysql_close();
?>
thanks a lot,
sifaka
 

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
205
Points
63
You need to create a user in the MySQL section of your cPanel. (Not your cPanel user name).

So if I went into my cPanel and create the user name corey, my cPanel user name would really be staff_corey because my cPanel name is staff, and the user name I just created is corey it automatically makes the user name staff_corey

You need to create this user name in the MySQL section then put it into the config part of the script. You do not want to include "@localhost"

-Corey
 
Last edited by a moderator:
Status
Not open for further replies.
Top