我正在尝试设置一个mysql数据库以从html表单中捕获信息,但是当我测试它时,它会返回以下错误。该文件与数据库位于同一服务器上。我的php位于错误之下。
警告:mysql_connect()[function.mysql-connect]:/home/westcl5/public_html/drjseminars.com/thankyou.php上的用户'inmoti6_ted_seminar'@'localhost'(使用密码:YES)拒绝访问92 无法连接:用户'inmoti6_ted_seminar'@'localhost'拒绝访问(使用密码:是)
if( $_POST )
{
$con = mysql_connect("localhost","inmoti6_ted_seminar","Polarbear5");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("inmoti6_westcl5_ted_sem", $con);
$users_firstName = $_POST['first_name'];
$users_lastName = $_POST['last_name'];
$users_street = $_POST['street'];
$users_street2 = $_POST['street2'];
$users_city = $_POST['city'];
$users_state = $_POST['state'];
$users_zip = $_POST['zip'];
$users_country = $_POST['country'];
$users_email = $_POST['email'];
$users_telephone = $_POST['telephone'];
$users_practice = $_POST['practice'];
$users_firstName = mysql_real_escape_string($users_firstName);
$users_lastName = mysql_real_escape_string($users_lastName);
$users_street = mysql_real_escape_string($users_street);
$users_street2 = mysql_real_escape_string($users_street2);
$users_city = mysql_real_escape_string($users_city);
$users_state = mysql_real_escape_string($users_state);
$users_zip = mysql_real_escape_string($users_zip);
$users_country = mysql_real_escape_string($users_country);
$users_email = mysql_real_escape_string($users_email);
$users_telephone = mysql_real_escape_string($users_telephone);
$users_practice = mysql_real_escape_string($users_practice);
$query = "
INSERT INTO `westcl5_ted_sem`.`ted_seminar` (`First Name`, `Last Name`, `E-mail`, `Phone #`, `Street Address`, `Street Address 2`, `City`, `State`, `Zip Code`, `Country`, `Practice`) VALUES ('$users_firstName', '$users_lastName', '$users_email', '$users_telephone', '$users_street', '$users_street2', '$users_city', '$users_state', '$users_zip', '$users_country', '$users_practice');";
mysql_query($query);
mysql_close($con);
}
答案 0 :(得分:0)
问题在于您的密码不匹配。尝试defulat $ CON =的mysql_connect( “本地主机”, '根', '');代替 $ con = mysql_connect(“localhost”,“inmoti6_ted_seminar”,“Polarbear5”);
在XAMPP上工作时我也收到了这个错误,但是通过使用我提到的上面那行解决了我的问题。
答案 1 :(得分:0)
您需要授予inmoti6_ted_seminar
用户权限。以root身份登录到mysql服务器并执行以下SQL,您当然可以设置他们拥有的权限,但我认为您只是想要INSERT
。
CREATE USER 'inmoti6_ted_seminar'@'localhost' IDENTIFIED BY 'Polarbear5';
GRANT INSERT ON inmoti6_westcl5_ted_sem.* TO 'inmoti6_ted_seminar'@'localhost';