PDA

View Full Version : Database Connection problem.


rajadilly
01-27-2006, 04:13 AM
I have a html file adduser.html which collects the datas from the users.
Now the when i try to execute the cgi script adduser.cgi which inserts the collected data in to the table called "user" which is in the "dvd" database. i get the following error. I use mysql.



c:\public_html>perl adduser.cgi
Name "dbi::errstr" used only once: possible typo at adduser.cgi line 18.
Dbi connect ('dvd','',...) failed. Acces denied for user 'ODBC'@'localhost' (using password:yes) at adduser.cgi line 14
Error opening database: Access denied for user 'ODBC'@'localhost' (using password: Yes)



When i installed the mysql it asked only the root password to me during the configuration of mysql. I am new to both perl and mysql so i dont know about this error. i also placed the cgi script which i used, below. I want to know the reason for this error in order to rectify the above mentioned error.



#!c:/perl/bin/perl -w

use CGI;
use DBI;
my $cgi=new CGI;

$name = $cgi->param("name");
$email=$cgi->param("email");
$phone=$cgi->param("phone");
$address=$cgi->param("address");
$username=$cgi->param("username");
$password=$cgi->param("password");

my $dbh=DBI->connect ("DBI:mysql:dvd","","autoraja")||
die "Error opening database: $DBI::errstr\n";
$sth=$dbh->prepare("insert into user(name, email, phone, address, username, password)
values($name, $email, $phone, $address, $username, $password)");
$sth->execute()||die "Unable to insert the value: $dbi::errstr\n";
$dbh=disconnect();

print "Content-type: text/html\n\n";
print "<HTML>";
print "<HEAD><TITLE>CGI Process: $name\n</TITLE></HEAD>";
print "<BODY>";

if($name eq "")
{
print "<H1>Invalid Name. Please Try Again.</H1></BODY></HTML>";
exit (0);
}

print "The name is <b>", $name, "</b>";
print "</BODY></HTML>";




Thanks in advance for your effort.

shyam
01-27-2006, 06:26 AM
this is a mysql config problem for the user ODBC

try running this query as root
GRANT USAGE ON *.* TO 'ODBC'@'localhost';
GRANT USAGE ON *.* TO 'ODBC'@'%';

rajadilly
01-27-2006, 06:40 AM
Thanks for your reply Shyam, Since i m not familiar with mysql can you please tell me wether i should issue that commands in the "Mysql>" promp or in some other place, if it is some other then please specify the procedure to issue these commands.and were should i issue these commands.